From cf144594a00ba2820ede56c328489a30a6d80b37 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Tue, 27 Mar 2018 00:13:57 +0200 Subject: [PATCH 01/18] Update version and ChangeLog for bip-0.9.0-rc3 release. --- ChangeLog | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8ed04b9..5a2a095 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,67 @@ +commit eaed46da1485ea81556ad255d7d56dc33daf1913 (G) +Author: Pierre-Louis Bonicoli +Date: Thu Mar 22 02:37:38 2018 +0100 + + Merge branch 'path_test_use_stat' + +commit 025689d8074b13f5229ee99b95190437194bae53 (G) +Author: Pierre-Louis Bonicoli +Date: Thu Mar 22 02:37:23 2018 +0100 + + Merge branch 'dh_param_not_mandatory' + +commit 948b41ef7a09b751df22bbd1c8f28b7bbe405a18 (G) +Author: Pierre-Louis Bonicoli +Date: Thu Mar 22 02:37:10 2018 +0100 + + Merge branch 'fix_path_construction_issue' + +commit 7834471f78c1af516df4bdbc193a805582e9f7fa (G) +Author: Pierre-Louis Bonicoli +Date: Wed Mar 21 11:32:46 2018 +0100 + + default value isn't used when path doesn't exist + +commit 13b2e3763541fc5045bbc09f14a5b0aae51558d0 (G) +Author: Pierre-Louis Bonicoli +Date: Wed Mar 21 11:12:21 2018 +0100 + + DH parameters are not always required + + for example ECDHE ciphers doesn't require DH parameters. + + Closes #499 + +commit 3afb16d795073d2aff9e2253619757a4e1e6e77c (G) +Author: Pierre-Louis Bonicoli +Date: Wed Mar 21 11:54:20 2018 +0100 + + checking path: use stat + + fopen was used because it's stdlib but stat is already used in other + parts + +commit 348737fab5c6529ba636056d40ec42f2cb18dd96 (G) +Author: Pierre-Louis Bonicoli +Date: Wed Mar 21 11:07:56 2018 +0100 + + Fix path construction + + Thanks to Renzokuken for pointing that ! + Closes #610 + +commit 385be75f7e904394dc4c9cccca9656c20c4c44f4 (G) +Author: Pierre-Louis Bonicoli +Date: Mon Feb 19 20:26:34 2018 +0100 + + Add -git to version string. + +commit 8ceebf1fd882f855d46a3d1d45dddbf50a357111 (G) +Author: Pierre-Louis Bonicoli +Date: Mon Feb 19 20:25:59 2018 +0100 + + Update version and ChangeLog for bip-0.9.0-rc2 release. + commit 901f54eff0f647442923f2ccf6f470f22e4c5ffe (G) Author: Pierre-Louis Bonicoli Date: Mon Feb 19 20:09:25 2018 +0100 diff --git a/configure.ac b/configure.ac index c0630c7..c60c7a7 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([Bip Sexy IRC Proxy], [0.9.0-rc2-git], +AC_INIT([Bip Sexy IRC Proxy], [0.9.0-rc3], [http://bip.milkypond.org/projects/bip/activity], [bip], [http://bip.milkypond.org/]) AM_INIT_AUTOMAKE([subdir-objects]) From b75345d6b552a3d06b21c843219393245ab7c4d3 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Tue, 27 Mar 2018 00:14:12 +0200 Subject: [PATCH 02/18] Add -git to version string. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index c60c7a7..5914c36 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([Bip Sexy IRC Proxy], [0.9.0-rc3], +AC_INIT([Bip Sexy IRC Proxy], [0.9.0-rc3-git], [http://bip.milkypond.org/projects/bip/activity], [bip], [http://bip.milkypond.org/]) AM_INIT_AUTOMAKE([subdir-objects]) From 34711f765339e3ec8548c06665feb5da713a649e Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 11 Nov 2018 18:16:14 -0500 Subject: [PATCH 03/18] Move automake file in src subdir, isolate main. In preparation for adding a unit test directory, move Makefile.am in src, and build a static libbip before linking a binary. --- Makefile.am | 18 +-- configure.ac | 3 +- src/Makefile.am | 24 ++++ src/bip.c | 263 +-------------------------------------- src/bip_main.c | 321 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 354 insertions(+), 275 deletions(-) create mode 100644 src/Makefile.am create mode 100644 src/bip_main.c diff --git a/Makefile.am b/Makefile.am index 3965c88..6356b46 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,20 +1,4 @@ -bin_PROGRAMS = src/bip src/bipmkpw -src_bip_SOURCES = src/conf.y src/lex.l \ - src/bip.c src/bip.h \ - src/connection.c src/connection.h \ - src/defaults.h \ - src/irc.c src/irc.h \ - src/line.c src/line.h \ - src/log.c src/log.h \ - src/md5.c src/md5.h \ - src/path_util.c src/path_util.h \ - src/tuple.h \ - src/util.c src/util.h -src_bipmkpw_SOURCES = src/bipmkpw.c src/md5.c src/util.c -AM_YFLAGS= -d -BUILT_SOURCES = src/conf.c src/conf.h src/lex.c - -AM_CFLAGS=-Wall -Wextra -Werror +SUBDIRS = src dist_man_MANS = bip.1 bip.conf.5 bipmkpw.1 diff --git a/configure.ac b/configure.ac index 5914c36..667d64e 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,7 @@ AC_CONFIG_HEADERS([src/config.h]) # Checks for programs AC_PROG_CC +AC_PROG_RANLIB AM_PROG_CC_C_O AC_PROG_INSTALL AM_PROG_LEX @@ -121,7 +122,7 @@ AS_IF([test "x$enable_pie" != "xno"], [ fi ]) -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT AS_IF([test "x$with_openssl" != "xno"], [ diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..cd2ea2b --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,24 @@ +noinst_LIBRARIES = libbip.a + +libbip_a_SOURCES = conf.y lex.l \ + bip.c bip.h \ + connection.c connection.h \ + defaults.h \ + irc.c irc.h \ + line.c line.h \ + log.c log.h \ + md5.c md5.h \ + path_util.c path_util.h \ + tuple.h \ + util.c util.h + +bin_PROGRAMS = bip bipmkpw + +bip_SOURCES = bip_main.c +bip_LDADD = libbip.a + +bipmkpw_SOURCES = bipmkpw.c md5.c util.c +AM_YFLAGS= -d +BUILT_SOURCES = conf.c conf.h lex.c + +#AM_CFLAGS=-Wall -Wextra -Werror diff --git a/src/bip.c b/src/bip.c index abb5afb..8552fdf 100644 --- a/src/bip.c +++ b/src/bip.c @@ -32,6 +32,8 @@ #include "line.h" #include "defaults.h" +#define S_CONF "bip.conf" + int sighup = 0; char *conf_log_root; @@ -56,6 +58,9 @@ int conf_log = DEFAULT_LOG; int conf_log_system = DEFAULT_LOG_SYSTEM; int conf_log_sync_interval = DEFAULT_LOG_SYNC_INTERVAL; +bip_t *_bip; +FILE *conf_global_log_file; + list_t *parse_conf(FILE *file, int *err); void conf_die(bip_t *bip, char *fmt, ...); static char *get_tuple_pvalue(list_t *tuple_l, int lex); @@ -63,6 +68,7 @@ void bip_notify(struct link_client *ic, char *fmt, ...); void adm_list_connections(struct link_client *ic, struct bipuser *bu); void free_conf(list_t *l); + #ifdef HAVE_OIDENTD #define OIDENTD_FILENAME ".oidentd.conf" #endif @@ -156,40 +162,6 @@ void conf_die(bip_t *bip, char *fmt, ...) va_end(ap); } -FILE *conf_global_log_file; - -static pid_t daemonize(void) -{ - switch (fork()) { - case -1: - fatal("Fork failed"); - break; - case 0: - break; - default: - _exit(0); - } - - if (setsid() < 0) - fatal("setsid() failed"); - - switch (fork()) { - case -1: - fatal("Fork failed"); - break; - case 0: - break; - default: - _exit(0); - } - - close(0); - close(1); - close(2); - /* This better be the very last action since fatal makes use of - * conf_global_log_file */ - return getpid(); -} /* RACE CONDITION! */ int do_pid_stuff(void) @@ -265,32 +237,6 @@ pid_is_there: return 0; } -#define S_CONF "bip.conf" - -static void usage(char *name) -{ - printf( -"Usage: %s [-f config_file] [-h] [-n]\n" -" -f config_file: Use config_file as the configuration file\n" -" If no config file is given %s will try to open ~/.bip/" S_CONF "\n" -" -n: Don't daemonize, log in stderr\n" -" -s: Bip HOME, default parent directory for client certificate,\n" -" configuration, logs, pid, oidentd\n" -" -v: Print version and exit\n" -" -h: This help\n", name, name); - exit(1); -} - -static void version() -{ - printf( -"Bip IRC Proxy - " PACKAGE_VERSION "\n" -"Copyright © Arnaud Cornet and Loïc Gomez (2004 - 2008)\n" -"Distributed under the GNU Public License Version 2\n"); -} - -bip_t *_bip; - void reload_config(int i) { (void)i; @@ -1100,23 +1046,6 @@ out_conf_error: return 0; } -static void log_file_setup(void) -{ - char buf[4096]; - - if (conf_log_system && conf_daemonize) { - if (conf_global_log_file && conf_global_log_file != stderr) - fclose(conf_global_log_file); - snprintf(buf, 4095, "%s/bip.log", conf_log_root); - FILE *f = fopen(buf, "a"); - if (!f) - fatal("Can't open %s: %s", buf, strerror(errno)); - conf_global_log_file = f; - } else { - conf_global_log_file = stderr; - } -} - void check_rlimits() { int r, cklim; @@ -1192,186 +1121,6 @@ void check_rlimits() mylog(LOG_WARN, "You can check your limits with `ulimit -a'"); } -int main(int argc, char **argv) -{ - FILE *conf = NULL; - char *confpath = NULL; - int ch; - int r, fd; - char buf[30]; - bip_t bip; - - bip_init(&bip); - _bip = &bip; - - conf_ip = bip_strdup("0.0.0.0"); - conf_port = 7778; - conf_css = 0; - - signal(SIGPIPE, SIG_IGN); - signal(SIGHUP, reload_config); - signal(SIGINT, bad_quit); - signal(SIGQUIT, bad_quit); - signal(SIGTERM, bad_quit); - signal(SIGXFSZ, rlimit_bigfile_reached); - signal(SIGXCPU, rlimit_cpu_reached); - - conf_log_root = NULL; - conf_log_format = bip_strdup(DEFAULT_LOG_FORMAT); - conf_log_level = DEFAULT_LOG_LEVEL; - conf_reconn_timer = DEFAULT_RECONN_TIMER; - conf_daemonize = 1; - conf_global_log_file = stderr; - conf_pid_file = NULL; -#ifdef HAVE_LIBSSL - conf_ssl_certfile = NULL; - conf_client_ciphers = NULL; - conf_server_default_ciphers = NULL; - conf_client_dh_file = NULL; -#endif - - while ((ch = getopt(argc, argv, "hvnf:s:")) != -1) { - switch (ch) { - case 'f': - confpath = bip_strdup(optarg); - break; - case 'n': - conf_daemonize = 0; - break; - case 's': - conf_biphome = bip_strdup(optarg); - break; - case 'v': - version(); - exit(0); - break; - default: - version(); - usage(argv[0]); - } - } - - umask(0027); - - check_rlimits(); - - char *home = NULL; /* oidentd path searching ignores conf_biphome */ - home = getenv("HOME"); - if (!home && !conf_biphome) { - conf_die(&bip, "no value for environment variable $HOME," - "use '-s' parameter"); - return 0; - } - - if (!conf_biphome) { - conf_biphome = bip_malloc(strlen(home) + strlen("/.bip") + 1); - strcpy(conf_biphome, home); - strcat(conf_biphome, "/.bip"); - } - -#ifdef HAVE_OIDENTD - if (!bip.oidentdpath) { - bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1 + - strlen(OIDENTD_FILENAME) + 1); - strcpy(bip.oidentdpath, conf_biphome); - strcat(bip.oidentdpath, "/"); - strcat(bip.oidentdpath, OIDENTD_FILENAME); - } -#endif - - if (!confpath) { - confpath = bip_malloc(strlen(conf_biphome) + 1 + - strlen(S_CONF) + 1); - strcpy(confpath, conf_biphome); - strcat(confpath, "/"); - strcat(confpath, S_CONF); - } - conf = fopen(confpath, "r"); - if (!conf) - fatal("config file not found"); - - r = fireup(&bip, conf); - fclose(conf); - if (!r) - fatal("Not starting: error in config file."); - - if (!conf_log_root) { - char *ap = "/logs"; - conf_log_root = bip_malloc(strlen(conf_biphome) + - strlen(ap) + 1); - strcpy(conf_log_root, conf_biphome); - strcat(conf_log_root, ap); - mylog(LOG_INFO, "Default log root: %s", conf_log_root); - } - if (!conf_pid_file) { - char *pid = "/bip.pid"; - conf_pid_file = bip_malloc(strlen(conf_biphome) + - strlen(pid) + 1); - strcpy(conf_pid_file, conf_biphome); - strcat(conf_pid_file, pid); - mylog(LOG_INFO, "Default pid file: %s", conf_pid_file); - } - -#ifdef HAVE_LIBSSL - if (conf_css) { - int e; - struct stat fs; - - if (!conf_ssl_certfile) { - conf_ssl_certfile = default_path(conf_biphome, "bip.pem", - "SSL certificate"); - } - assert_path_exists(conf_ssl_certfile); - - e = stat(conf_ssl_certfile, &fs); - if (e) - mylog(LOG_WARN, "Unable to check PEM file, stat(%s): " - "%s", conf_ssl_certfile, strerror(errno)); - else if ((fs.st_mode & S_IROTH) | (fs.st_mode & S_IWOTH)) - mylog(LOG_ERROR, "PEM file %s should not be world " - "readable / writable. Please fix the modes.", - conf_ssl_certfile); - - if (conf_client_dh_file) { - assert_path_exists(conf_client_dh_file); - } - } -#endif - - check_dir(conf_log_root, 1); - fd = do_pid_stuff(); - pid_t pid = 0; - - log_file_setup(); - if (conf_daemonize) - pid = daemonize(); - else - pid = getpid(); - snprintf(buf, 29, "%ld\n", (long unsigned int)pid); - write(fd, buf, strlen(buf)); - close(fd); - - bip.listener = listen_new(conf_ip, conf_port, conf_css); - if (!bip.listener || bip.listener->connected == CONN_ERROR) - fatal("Could not create listening socket"); - - for (;;) { - irc_main(&bip); - - sighup = 0; - - conf = fopen(confpath, "r"); - if (!conf) - fatal("%s config file not found", confpath); - fireup(&bip, conf); - fclose(conf); - - /* re-open to allow logfile rotate */ - log_file_setup(); - } - return 1; -} - #define RET_STR_LEN 256 #define LINE_SIZE_LIM 70 void adm_print_connection(struct link_client *ic, struct link *lnk, diff --git a/src/bip_main.c b/src/bip_main.c new file mode 100644 index 0000000..5c7fa1f --- /dev/null +++ b/src/bip_main.c @@ -0,0 +1,321 @@ +/* + * $Id: bip.c,v 1.39 2005/04/21 06:58:50 nohar Exp $ + * + * This file is part of the bip project + * Copyright (C) 2004 2005 Arnaud Cornet and Loïc Gomez + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file "COPYING" for the exact licensing terms. + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "irc.h" +#include "conf.h" +#include "path_util.h" +#include "tuple.h" +#include "log.h" +#include "bip.h" +#include "line.h" +#include "defaults.h" + +#define S_CONF "bip.conf" + +extern int sighup; +extern char *conf_log_root; +extern char *conf_log_format; +extern int conf_log_level; +extern char *conf_ip; +extern unsigned short conf_port; +extern int conf_css; +#ifdef HAVE_LIBSSL +extern char *conf_ssl_certfile; +extern char *conf_client_ciphers; +extern char *conf_client_dh_file; +extern char *conf_server_default_ciphers; +#endif +extern int conf_daemonize; +extern char *conf_pid_file; +extern char *conf_biphome; +extern int conf_reconn_timer; + +/* log options, for sure the trickiest :) */ +extern int conf_log; +extern int conf_log_system; +extern int conf_log_sync_interval; +extern bip_t *_bip; +extern FILE *conf_global_log_file; + +void reload_config(int i); +void bad_quit(int i); +void check_rlimits(); +void rlimit_cpu_reached(int i); +void rlimit_bigfile_reached(int i); +void conf_die(bip_t *bip, char *fmt, ...); +int fireup(bip_t *bip, FILE *conf); +int do_pid_stuff(void); + +static void usage(char *name) +{ + printf( +"Usage: %s [-f config_file] [-h] [-n]\n" +" -f config_file: Use config_file as the configuration file\n" +" If no config file is given %s will try to open ~/.bip/" S_CONF "\n" +" -n: Don't daemonize, log in stderr\n" +" -s: Bip HOME, default parent directory for client certificate,\n" +" configuration, logs, pid, oidentd\n" +" -v: Print version and exit\n" +" -h: This help\n", name, name); + exit(1); +} + +static void version() +{ + printf( +"Bip IRC Proxy - " PACKAGE_VERSION "\n" +"Copyright © Arnaud Cornet and Loïc Gomez (2004 - 2008)\n" +"Distributed under the GNU Public License Version 2\n"); +} + +static void log_file_setup(void) +{ + char buf[4096]; + + if (conf_log_system && conf_daemonize) { + if (conf_global_log_file && conf_global_log_file != stderr) + fclose(conf_global_log_file); + snprintf(buf, 4095, "%s/bip.log", conf_log_root); + FILE *f = fopen(buf, "a"); + if (!f) + fatal("Can't open %s: %s", buf, strerror(errno)); + conf_global_log_file = f; + } else { + conf_global_log_file = stderr; + } +} + +static pid_t daemonize(void) +{ + switch (fork()) { + case -1: + fatal("Fork failed"); + break; + case 0: + break; + default: + _exit(0); + } + + if (setsid() < 0) + fatal("setsid() failed"); + + switch (fork()) { + case -1: + fatal("Fork failed"); + break; + case 0: + break; + default: + _exit(0); + } + + close(0); + close(1); + close(2); + /* This better be the very last action since fatal makes use of + * conf_global_log_file */ + return getpid(); +} + +int main(int argc, char **argv) +{ + FILE *conf = NULL; + char *confpath = NULL; + int ch; + int r, fd; + char buf[30]; + bip_t bip; + + bip_init(&bip); + _bip = &bip; + + conf_ip = bip_strdup("0.0.0.0"); + conf_port = 7778; + conf_css = 0; + + signal(SIGPIPE, SIG_IGN); + signal(SIGHUP, reload_config); + signal(SIGINT, bad_quit); + signal(SIGQUIT, bad_quit); + signal(SIGTERM, bad_quit); + signal(SIGXFSZ, rlimit_bigfile_reached); + signal(SIGXCPU, rlimit_cpu_reached); + + conf_log_root = NULL; + conf_log_format = bip_strdup(DEFAULT_LOG_FORMAT); + conf_log_level = DEFAULT_LOG_LEVEL; + conf_reconn_timer = DEFAULT_RECONN_TIMER; + conf_daemonize = 1; + conf_global_log_file = stderr; + conf_pid_file = NULL; +#ifdef HAVE_LIBSSL + conf_ssl_certfile = NULL; + conf_client_ciphers = NULL; + conf_server_default_ciphers = NULL; + conf_client_dh_file = NULL; +#endif + + while ((ch = getopt(argc, argv, "hvnf:s:")) != -1) { + switch (ch) { + case 'f': + confpath = bip_strdup(optarg); + break; + case 'n': + conf_daemonize = 0; + break; + case 's': + conf_biphome = bip_strdup(optarg); + break; + case 'v': + version(); + exit(0); + break; + default: + version(); + usage(argv[0]); + } + } + + umask(0027); + + check_rlimits(); + + char *home = NULL; /* oidentd path searching ignores conf_biphome */ + home = getenv("HOME"); + if (!home && !conf_biphome) { + conf_die(&bip, "no value for environment variable $HOME," + "use '-s' parameter"); + return 0; + } + + if (!conf_biphome) { + conf_biphome = bip_malloc(strlen(home) + strlen("/.bip") + 1); + strcpy(conf_biphome, home); + strcat(conf_biphome, "/.bip"); + } + +#ifdef HAVE_OIDENTD + if (!bip.oidentdpath) { + bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1 + + strlen(OIDENTD_FILENAME) + 1); + strcpy(bip.oidentdpath, conf_biphome); + strcat(bip.oidentdpath, "/"); + strcat(bip.oidentdpath, OIDENTD_FILENAME); + } +#endif + + if (!confpath) { + confpath = bip_malloc(strlen(conf_biphome) + 1 + + strlen(S_CONF) + 1); + strcpy(confpath, conf_biphome); + strcat(confpath, "/"); + strcat(confpath, S_CONF); + } + conf = fopen(confpath, "r"); + if (!conf) + fatal("config file not found"); + + r = fireup(&bip, conf); + fclose(conf); + if (!r) + fatal("Not starting: error in config file."); + + if (!conf_log_root) { + char *ap = "/logs"; + conf_log_root = bip_malloc(strlen(conf_biphome) + + strlen(ap) + 1); + strcpy(conf_log_root, conf_biphome); + strcat(conf_log_root, ap); + mylog(LOG_INFO, "Default log root: %s", conf_log_root); + } + if (!conf_pid_file) { + char *pid = "/bip.pid"; + conf_pid_file = bip_malloc(strlen(conf_biphome) + + strlen(pid) + 1); + strcpy(conf_pid_file, conf_biphome); + strcat(conf_pid_file, pid); + mylog(LOG_INFO, "Default pid file: %s", conf_pid_file); + } + +#ifdef HAVE_LIBSSL + if (conf_css) { + int e; + struct stat fs; + + if (!conf_ssl_certfile) { + conf_ssl_certfile = default_path(conf_biphome, "bip.pem", + "SSL certificate"); + } + assert_path_exists(conf_ssl_certfile); + + e = stat(conf_ssl_certfile, &fs); + if (e) + mylog(LOG_WARN, "Unable to check PEM file, stat(%s): " + "%s", conf_ssl_certfile, strerror(errno)); + else if ((fs.st_mode & S_IROTH) | (fs.st_mode & S_IWOTH)) + mylog(LOG_ERROR, "PEM file %s should not be world " + "readable / writable. Please fix the modes.", + conf_ssl_certfile); + + if (conf_client_dh_file) { + assert_path_exists(conf_client_dh_file); + } + } +#endif + + check_dir(conf_log_root, 1); + fd = do_pid_stuff(); + pid_t pid = 0; + + log_file_setup(); + if (conf_daemonize) + pid = daemonize(); + else + pid = getpid(); + snprintf(buf, 29, "%ld\n", (long unsigned int)pid); + write(fd, buf, strlen(buf)); + close(fd); + + bip.listener = listen_new(conf_ip, conf_port, conf_css); + if (!bip.listener || bip.listener->connected == CONN_ERROR) + fatal("Could not create listening socket"); + + for (;;) { + irc_main(&bip); + + sighup = 0; + + conf = fopen(confpath, "r"); + if (!conf) + fatal("%s config file not found", confpath); + fireup(&bip, conf); + fclose(conf); + + /* re-open to allow logfile rotate */ + log_file_setup(); + } + return 1; +} From aa35b372b47c7736a9efa6c6703ed1ffd23b1c36 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 12 Nov 2018 22:55:58 -0500 Subject: [PATCH 04/18] Add unit tests. Add an optional build dependency on check and add an initial test case. --- Makefile.am | 2 +- configure.ac | 11 +++- src/Makefile.am | 2 +- src/line.c | 12 ---- src/line.h | 1 - tests/Makefile.am | 5 ++ tests/check_line.c | 134 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 tests/Makefile.am create mode 100644 tests/check_line.c diff --git a/Makefile.am b/Makefile.am index 6356b46..12442b8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = src +SUBDIRS = src . tests dist_man_MANS = bip.1 bip.conf.5 bipmkpw.1 diff --git a/configure.ac b/configure.ac index 667d64e..44d9eb0 100644 --- a/configure.ac +++ b/configure.ac @@ -69,6 +69,7 @@ AC_ARG_ENABLE([oidentd], AS_HELP_STRING([--enable-oidentd], [Enable oidentd support (bip overwrites ~/.oidentd.conf with this on!)])) AC_ARG_ENABLE([pie], AS_HELP_STRING([--disable-pie], [Do not build a position independent executable])) +AC_ARG_ENABLE([tests], AS_HELP_STRING([--enable-tests], [Build tests])) AM_CONDITIONAL(DEBUG, test x$enable_debug = xyes) AS_IF([test "x$enable_debug" = "xyes"], [ @@ -122,7 +123,12 @@ AS_IF([test "x$enable_pie" != "xno"], [ fi ]) -AC_CONFIG_FILES([Makefile src/Makefile]) +AS_IF([test "x$enable_tests" != "xno"], [ + PKG_CHECK_MODULES([CHECK], [check >= 0.9.6]) +]) + + +AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile]) AC_OUTPUT AS_IF([test "x$with_openssl" != "xno"], [ @@ -131,3 +137,6 @@ echo OPENSSL: yes echo DEBUG: $enable_debug $backtrace echo OIDENTD: $enable_oidentd echo PIE: $enable_pie +AS_IF([test "x$enable_tests" != "xno"], [ +echo TESTS: $enable_tests +]) diff --git a/src/Makefile.am b/src/Makefile.am index cd2ea2b..5d7f516 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,4 +21,4 @@ bipmkpw_SOURCES = bipmkpw.c md5.c util.c AM_YFLAGS= -d BUILT_SOURCES = conf.c conf.h lex.c -#AM_CFLAGS=-Wall -Wextra -Werror +AM_CFLAGS=-Wall -Wextra -Werror diff --git a/src/line.c b/src/line.c index 6aef563..73f35cc 100644 --- a/src/line.c +++ b/src/line.c @@ -213,15 +213,3 @@ void irc_line_free(struct line *l) free(l->origin); free(l); } - -void irc_line_free_args(char **elemv, int elemc) -{ - int i; - - if (elemc == 0) - return; - for (i = 0; i < elemc; i++) - free(elemv[i]); - free(elemv); -} - diff --git a/src/line.h b/src/line.h index e897d8b..52a8d93 100644 --- a/src/line.h +++ b/src/line.h @@ -99,7 +99,6 @@ int irc_line_count(struct line *line); char *irc_line_pop(struct line *l); int irc_line_elem_equals(struct line *line, int elem, const char *cmp); int irc_line_elem_case_equals(struct line *line, int elem, const char *cmp); -void irc_line_free_args(char **elemv, int elemc); void irc_line_drop(struct line *line, int elem); #endif diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..1d781a8 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,5 @@ +TESTS = check_line +check_PROGRAMS = check_line +check_line_SOURCES = check_line.c $(top_builddir)/src/line.h +check_line_CFLAGS = @CHECK_CFLAGS@ +check_line_LDADD = $(top_builddir)/src/libbip.a @CHECK_LIBS@ diff --git a/tests/check_line.c b/tests/check_line.c new file mode 100644 index 0000000..a4f8833 --- /dev/null +++ b/tests/check_line.c @@ -0,0 +1,134 @@ +#include +#include "../src/line.h" + +START_TEST(test_line_init) +{ + struct line line; + irc_line_init(&line); + irc_line_append(&line, "line"); + char *hi_string = irc_line_to_string(&line); + ck_assert_str_eq(hi_string, "line\r\n"); + free(hi_string); + _irc_line_deinit(&line); + + struct line *line2 = irc_line_new(); + irc_line_append(line2, "line"); + hi_string = irc_line_to_string(line2); + ck_assert_str_eq(hi_string, "line\r\n"); + free(hi_string); + irc_line_free(line2); +} +END_TEST + +START_TEST(test_line_parse) +{ + struct line *line = irc_line_new_from_string( + ":origin COMMAND parameter1 parameter2 " + ":multi word parameter\r\n"); + ck_assert_int_eq(irc_line_count(line), 4); + ck_assert(irc_line_includes(line, 0)); + ck_assert(irc_line_includes(line, 3)); + ck_assert(!irc_line_includes(line, 4)); + ck_assert_str_eq(line->origin, "origin"); + ck_assert_str_eq(irc_line_elem(line, 0), "COMMAND"); + ck_assert_str_eq(irc_line_elem(line, 1), "parameter1"); + ck_assert_str_eq(irc_line_elem(line, 2), "parameter2"); + ck_assert_str_eq(irc_line_elem(line, 3), "multi word parameter\r\n"); + irc_line_free(line); + + line = irc_line_new_from_string( + "COMMAND parameter1 parameter2 :multi word parameter\r\n"); + ck_assert_int_eq(irc_line_count(line), 4); + ck_assert(irc_line_includes(line, 0)); + ck_assert(irc_line_includes(line, 3)); + ck_assert(!irc_line_includes(line, 4)); + ck_assert_str_eq(irc_line_elem(line, 0), "COMMAND"); + ck_assert_str_eq(irc_line_elem(line, 1), "parameter1"); + ck_assert_str_eq(irc_line_elem(line, 2), "parameter2"); + ck_assert_str_eq(irc_line_elem(line, 3), "multi word parameter\r\n"); + irc_line_free(line); + + line = irc_line_new_from_string(":origin COMMAND\r\n"); + ck_assert_str_eq(line->origin, "origin"); + ck_assert_int_eq(irc_line_count(line), 1); + ck_assert(irc_line_includes(line, 0)); + ck_assert(!irc_line_includes(line, 1)); + ck_assert_str_eq(irc_line_elem(line, 0), "COMMAND\r\n"); + irc_line_free(line); +} +END_TEST + +START_TEST(test_elem_equals) +{ + struct line *line = irc_line_new_from_string( + ":origin COMMAND parameter1 parameter2 " + ":multi word parameter\r\n"); + ck_assert(irc_line_elem_equals(line, 0, "COMMAND")); + ck_assert(irc_line_elem_case_equals(line, 0, "command")); + ck_assert(!irc_line_elem_equals(line, 0, "notcommand")); + ck_assert(!irc_line_elem_case_equals(line, 0, "notcommand")); + irc_line_free(line); +} +END_TEST + +START_TEST(test_line_pop) +{ + struct line *line = irc_line_new_from_string( + ":origin COMMAND parameter1 parameter2 " + ":multi word parameter\r\n"); + char *top = irc_line_pop(line); + ck_assert_str_eq(top, "multi word parameter\r\n"); + free(top); + top = irc_line_pop(line); + ck_assert_str_eq(top, "parameter2"); + free(top); + irc_line_free(line); +} +END_TEST + +START_TEST(test_line_drop) +{ + struct line *line = irc_line_new_from_string( + ":origin COMMAND parameter1 parameter2 " + ":multi word parameter\r\n"); + irc_line_drop(line, 1); + ck_assert(irc_line_elem_equals(line, 0, "COMMAND")); + ck_assert(irc_line_elem_equals(line, 1, "parameter2")); + irc_line_drop(line, 0); + ck_assert(irc_line_elem_equals(line, 0, "parameter2")); + irc_line_free(line); +} +END_TEST + +Suite *money_suite(void) +{ + Suite *s; + TCase *tc_core; + + s = suite_create("bip"); + + tc_core = tcase_create("core"); + + tcase_add_test(tc_core, test_line_init); + tcase_add_test(tc_core, test_line_parse); + tcase_add_test(tc_core, test_elem_equals); + tcase_add_test(tc_core, test_line_pop); + suite_add_tcase(s, tc_core); + + return s; +} + +int main(void) +{ + int number_failed; + Suite *s; + SRunner *sr; + + s = money_suite(); + sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} From e222e1c986ef136b31d98dd444d3ea96827b4bea Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 18 Nov 2018 08:15:31 -0500 Subject: [PATCH 05/18] Add .gitignore. --- .gitignore | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4f545c --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +# http://www.gnu.org/software/automake + +Makefile.in +/ar-lib +/mdate-sh +/py-compile +/test-driver +/ylwrap + +# http://www.gnu.org/software/autoconf + +autom4te.cache +/autoscan.log +/autoscan-*.log +/aclocal.m4 +/compile +/config.guess +/config.h.in +/config.log +/config.status +/config.sub +/configure +/configure.scan +/depcomp +/install-sh +/missing +/stamp-h1 + +# https://www.gnu.org/software/libtool/ + +/ltmain.sh + +# http://www.gnu.org/software/texinfo + +/texinfo.tex + +# http://www.gnu.org/software/m4/ + +m4/libtool.m4 +m4/ltoptions.m4 +m4/ltsugar.m4 +m4/ltversion.m4 +m4/lt~obsolete.m4 From fabaec9d807e9ac106790f282953ffa5c3aa055a Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 18 Nov 2018 08:18:42 -0500 Subject: [PATCH 06/18] More files in .gitignore --- .gitignore | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.gitignore b/.gitignore index f4f545c..24dbce5 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,17 @@ m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 + +# Makefiles +Makefile +src/.deps/ +src/Makefile +tests/.deps/ +tests/Makefile + +# Generated code +src/conf.c +src/conf.h +src/config.h +src/config.h.in +src/lex.c From a80e74bbdc84862342441e0c5bfb3c22faf4d534 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 18 Nov 2018 08:19:26 -0500 Subject: [PATCH 07/18] Add .clang-format file. --- .clang-format | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..5a4737c --- /dev/null +++ b/.clang-format @@ -0,0 +1,21 @@ +--- +BasedOnStyle: LLVM +Language: Cpp +IndentWidth: 8 +UseTab: Always +BreakBeforeBraces: Linux +AlwaysBreakBeforeMultilineStrings: true +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +IndentCaseLabels: false +AlignEscapedNewlinesLeft: false +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AlignAfterOpenBracket: true +SpaceAfterCStyleCast: false +MaxEmptyLinesToKeep: 2 +BreakBeforeBinaryOperators: NonAssignment +BreakStringLiterals: false +SortIncludes: false +ContinuationIndentWidth: 8 From c0fafe669d08170b171601d49cf5542a68692a71 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 18 Nov 2018 09:10:16 -0500 Subject: [PATCH 08/18] Simplify autotools configuration. --- configure.ac | 56 ++++--------------------------------------------- src/Makefile.am | 2 -- src/irc.c | 20 ++++++++++-------- src/log.c | 5 ++--- 4 files changed, 17 insertions(+), 66 deletions(-) diff --git a/configure.ac b/configure.ac index 44d9eb0..ad837ed 100644 --- a/configure.ac +++ b/configure.ac @@ -1,67 +1,19 @@ AC_PREREQ([2.69]) -AC_INIT([Bip Sexy IRC Proxy], [0.9.0-rc3-git], - [http://bip.milkypond.org/projects/bip/activity], [bip], - [http://bip.milkypond.org/]) -AM_INIT_AUTOMAKE([subdir-objects]) +AC_INIT([Bip IRC Proxy],[0.9.0-rc3-git],[http://bip.milkypond.org/projects/bip/activity],[bip],[http://bip.milkypond.org/]) +AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AM_MAINTAINER_MODE -m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES]) -AC_CONFIG_SRCDIR([src/bip.h]) + AC_CONFIG_HEADERS([src/config.h]) # Checks for programs AC_PROG_CC +AM_PROG_AR AC_PROG_RANLIB -AM_PROG_CC_C_O AC_PROG_INSTALL AM_PROG_LEX AC_PROG_YACC -# AC_PROG_YACC falls back to YACC = "yacc" if bison or byacc are not found, -# but it does not mean it is present -AS_IF([test x"$YACC" = "xyacc"], [ - AC_CHECK_PROG([YACC_EXISTS], [yacc], [yes], [no]) - AS_IF([test x"$YACC_EXISTS" != xyes], [ - YACC=${am_missing_run}yacc - ]) -]) - -# Checks for header files. -AC_FUNC_ALLOCA -AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h malloc.h \ - netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h \ - sys/socket.h sys/time.h termios.h unistd.h]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_C_INLINE -AC_TYPE_INT16_T -AC_TYPE_INT32_T -AC_TYPE_INT8_T -AC_TYPE_PID_T -AC_TYPE_SIZE_T -AC_TYPE_SSIZE_T -AC_TYPE_UINT16_T -AC_TYPE_UINT32_T -AC_TYPE_UINT8_T - -AX_C___ATTRIBUTE__ -AH_BOTTOM([ -/* Unused attributes such as function parameters (GCC extension) */ -#ifdef HAVE___ATTRIBUTE__ -# define UNUSED(ATTRIBUTE) ATTRIBUTE __attribute__((unused)) -#else -# define UNUSED(ATTRIBUTE) ATTRIBUTE -#endif]) - -# Checks for library functions. -AC_FUNC_FORK -AC_FUNC_MALLOC -AC_FUNC_MKTIME -AC_FUNC_REALLOC -AC_CHECK_FUNCS(clock_gettime ftruncate gethostname gettimeofday localtime_r memmove) -AC_CHECK_FUNCS(memset mkdir select socket strcasecmp strchr strcspn strdup strerror) -AC_CHECK_FUNCS(strrchr strstr) # Deal with parameters - AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Enable debug build])) AC_ARG_WITH([openssl], AS_HELP_STRING([--without-openssl], [Disable SSL using OpenSSL])) diff --git a/src/Makefile.am b/src/Makefile.am index 5d7f516..04b6ee7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,5 +20,3 @@ bip_LDADD = libbip.a bipmkpw_SOURCES = bipmkpw.c md5.c util.c AM_YFLAGS= -d BUILT_SOURCES = conf.c conf.h lex.c - -AM_CFLAGS=-Wall -Wextra -Werror diff --git a/src/irc.c b/src/irc.c index f46f4dd..7a1cbbf 100644 --- a/src/irc.c +++ b/src/irc.c @@ -51,8 +51,8 @@ static void ls_set_nick(struct link_server *ircs, char *nick); static void server_set_chanmodes(struct link_server *l, const char *chanmodes); static void server_set_prefix(struct link_server *l, const char *prefix); static void server_init_modes(struct link_server *s); -static int get_index(const char* str, char car); -static int fls(int v); +static int bip_get_index(const char* str, char car); +static int bip_fls(int v); #ifdef HAVE_OIDENTD #define OIDENTD_FILENAME ".oidentd.conf" @@ -137,7 +137,7 @@ list_t *channel_name_list(struct link_server *server, struct channel *c) // prepend symbol corresponding to the usermode int msb; - if ((msb = fls(ovmask))) { + if ((msb = bip_fls(ovmask))) { str[len] = server->prefixes[msb - 1]; str[++len] = 0; } @@ -314,8 +314,9 @@ static int irc_352(struct link_server *server, struct line *line) return OK_COPY_WHO; } -static int irc_315(struct link_server *server, UNUSED(struct line *l)) +static int irc_315(struct link_server *server, struct line *l) { + (void)l; struct link *link = LINK(server); if (link->who_client) { if (link->who_client->who_count == 0) { @@ -1400,7 +1401,7 @@ static int irc_353(struct link_server *server, struct line *line) long int ovmask = 0; /* some ircds (e.g. unreal) may display several flags for the same nick */ - while ((index = get_index(server->prefixes, *names))) { + while ((index = bip_get_index(server->prefixes, *names))) { ovmask |= 1 << index; names++; } @@ -1446,8 +1447,9 @@ static int irc_367(struct link_server *server, struct line *l) } /* same as irc_315 */ -static int irc_368(struct link_server *server, UNUSED(struct line *l)) +static int irc_368(struct link_server *server, struct line *l) { + (void)l; struct link *link = LINK(server); if (link->who_client) { if (link->who_client->who_count == 0) { @@ -1683,7 +1685,7 @@ static int irc_mode_channel(struct link_server *s, struct channel *channel, channel->key = NULL; } } - } else if ((index = get_index(s->usermodes, *mode))) { + } else if ((index = bip_get_index(s->usermodes, *mode))) { nick = irc_line_elem(line, cur_arg + 3); if (!hash_includes(&channel->ovmasks, nick)) @@ -2713,7 +2715,7 @@ static void server_set_prefix(struct link_server *s, const char *modes) } // Return the position (*1 based*) of car in str, else -1 -static int get_index(const char* str, char car) +static int bip_get_index(const char* str, char car) { char *cur; if ((cur = strchr(str, car))) @@ -2722,7 +2724,7 @@ static int get_index(const char* str, char car) return 0; } -static int fls(int v) +static int bip_fls(int v) { unsigned int r = 0; while (v >>= 1) diff --git a/src/log.c b/src/log.c index 457337a..de53430 100644 --- a/src/log.c +++ b/src/log.c @@ -11,14 +11,13 @@ * See the file "COPYING" for the exact licensing terms. */ -#define _XOPEN_SOURCE 500 - #include "config.h" #include "log.h" #include "irc.h" #include "util.h" #include #include +#include extern int errno; extern int log_level; @@ -713,7 +712,7 @@ void log_reset_all(log_t *logdata) if (ischannel(*hash_it_key(&hi))) log_reset(store); else - list_add_last(&drop, strdup(hash_it_key(&hi))); + list_add_last(&drop, bip_strdup(hash_it_key(&hi))); } char *name; From 87f34153303becc9eeef5d331992b67557ce9a46 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 18 Nov 2018 14:23:06 -0500 Subject: [PATCH 09/18] Fewer build options. Eagerly depend on openssl and check, build degraded without. --- configure.ac | 67 +++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/configure.ac b/configure.ac index ad837ed..07aa968 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.69]) AC_INIT([Bip IRC Proxy],[0.9.0-rc3-git],[http://bip.milkypond.org/projects/bip/activity],[bip],[http://bip.milkypond.org/]) -AM_INIT_AUTOMAKE([foreign -Wall -Werror]) +AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror]) AM_MAINTAINER_MODE AC_CONFIG_HEADERS([src/config.h]) @@ -12,6 +12,8 @@ AC_PROG_RANLIB AC_PROG_INSTALL AM_PROG_LEX AC_PROG_YACC +m4_ifndef([PKG_PROG_PKG_CONFIG], [m4_fatal([Please install pkg-config.])]) +PKG_PROG_PKG_CONFIG # Deal with parameters AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Enable debug build])) @@ -21,7 +23,6 @@ AC_ARG_ENABLE([oidentd], AS_HELP_STRING([--enable-oidentd], [Enable oidentd support (bip overwrites ~/.oidentd.conf with this on!)])) AC_ARG_ENABLE([pie], AS_HELP_STRING([--disable-pie], [Do not build a position independent executable])) -AC_ARG_ENABLE([tests], AS_HELP_STRING([--enable-tests], [Build tests])) AM_CONDITIONAL(DEBUG, test x$enable_debug = xyes) AS_IF([test "x$enable_debug" = "xyes"], [ @@ -41,46 +42,34 @@ AS_IF([test "x$enable_oidentd" = "xyes"], [ enable_oidentd=no ]) -AS_IF([test "x$with_openssl" != "xno"], [ - AC_CHECK_LIB(crypto, CRYPTO_new_ex_data, [], [ - AC_MSG_ERROR([library 'crypto' is required for OpenSSL support]) - with_openssl=no - ], -lcrypto) - AC_CHECK_LIB(ssl, SSL_read, [], [ - AC_MSG_ERROR([library 'ssl' is required for OpenSSL support]) - with_openssl=no - ], -lssl) -], [ - with_openssl=no +PKG_CHECK_MODULES(OPENSSL, [libssl >= 0.9.8 libcrypto >= 0.9.8], [with_openssl=yes], [with_openssl=no]) + +AC_CACHE_CHECK([whether $CC accepts PIE flags], [ap_cv_cc_pie], [ + save_CFLAGS=$CFLAGS + save_LDFLAGS=$LDFLAGS + CFLAGS="$CFLAGS -fPIE" + LDFLAGS="$LDFLAGS -pie" + AC_RUN_IFELSE([AC_LANG_SOURCE([[static int foo[30000]; int main () { return 0; }]])], + [ap_cv_cc_pie=yes], + [ap_cv_cc_pie=no], + [ap_cv_cc_pie=yes] + ) + CFLAGS=$save_CFLAGS + LDFLAGS=$save_LDFLAGS ]) +if test "$ap_cv_cc_pie" = "yes"; then + CFLAGS="$CFLAGS -fPIE" + LDFLAGS="$LDFLAGS -pie" + enable_pie=yes +fi -AS_IF([test "x$enable_pie" != "xno"], [ - AC_CACHE_CHECK([whether $CC accepts PIE flags], [ap_cv_cc_pie], [ - save_CFLAGS=$CFLAGS - save_LDFLAGS=$LDFLAGS - CFLAGS="$CFLAGS -fPIE" - LDFLAGS="$LDFLAGS -pie" - AC_RUN_IFELSE([AC_LANG_SOURCE([[static int foo[30000]; int main () { return 0; }]])], - [ap_cv_cc_pie=yes], - [ap_cv_cc_pie=no], - [ap_cv_cc_pie=yes] - ) - CFLAGS=$save_CFLAGS - LDFLAGS=$save_LDFLAGS - ]) - if test "$ap_cv_cc_pie" = "yes"; then - CFLAGS="$CFLAGS -fPIE" - LDFLAGS="$LDFLAGS -pie" - enable_pie=yes - fi -]) - -AS_IF([test "x$enable_tests" != "xno"], [ - PKG_CHECK_MODULES([CHECK], [check >= 0.9.6]) -]) +PKG_CHECK_MODULES([CHECK], [check >= 0.9.6], [ + AC_CONFIG_FILES([tests/Makefile]) + enable_tests=yes + ], [ enable_tests=no ]) -AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile]) +AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT AS_IF([test "x$with_openssl" != "xno"], [ @@ -89,6 +78,4 @@ echo OPENSSL: yes echo DEBUG: $enable_debug $backtrace echo OIDENTD: $enable_oidentd echo PIE: $enable_pie -AS_IF([test "x$enable_tests" != "xno"], [ echo TESTS: $enable_tests -]) From 7844716af5d1c655989afbfc0c3cc12665e3884b Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 18 Nov 2018 14:30:17 -0500 Subject: [PATCH 10/18] Fewer configure options. Use pkg-config to detect openssl. Eagerly use backtrace if provided by libc. --- configure.ac | 28 +++++++--------------------- src/util.c | 5 ++--- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/configure.ac b/configure.ac index 07aa968..eca41e8 100644 --- a/configure.ac +++ b/configure.ac @@ -15,25 +15,8 @@ AC_PROG_YACC m4_ifndef([PKG_PROG_PKG_CONFIG], [m4_fatal([Please install pkg-config.])]) PKG_PROG_PKG_CONFIG -# Deal with parameters -AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Enable debug build])) -AC_ARG_WITH([openssl], AS_HELP_STRING([--without-openssl], - [Disable SSL using OpenSSL])) AC_ARG_ENABLE([oidentd], AS_HELP_STRING([--enable-oidentd], [Enable oidentd support (bip overwrites ~/.oidentd.conf with this on!)])) -AC_ARG_ENABLE([pie], AS_HELP_STRING([--disable-pie], - [Do not build a position independent executable])) - -AM_CONDITIONAL(DEBUG, test x$enable_debug = xyes) -AS_IF([test "x$enable_debug" = "xyes"], [ - AC_CHECK_FUNC(backtrace_symbols_fd, [ - AC_DEFINE(HAVE_BACKTRACE, [], [Use glibc backtrace on fatal()]) - LDFLAGS="-rdynamic $LDFLAGS" - backtrace="(with backtrace)" - ]) -], [ - enable_debug=no -]) AM_CONDITIONAL(OIDENTD, test x$enable_identd = xyes) AS_IF([test "x$enable_oidentd" = "xyes"], [ @@ -68,14 +51,17 @@ PKG_CHECK_MODULES([CHECK], [check >= 0.9.6], [ enable_tests=yes ], [ enable_tests=no ]) +AC_CHECK_FUNC(backtrace_symbols_fd, [ + AC_DEFINE(HAVE_BACKTRACE, [], [Use glibc backtrace on fatal()]) + LDFLAGS="-rdynamic $LDFLAGS" + backtrace="(with backtrace)" +]) + AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT -AS_IF([test "x$with_openssl" != "xno"], [ -echo OPENSSL: yes -]) -echo DEBUG: $enable_debug $backtrace +echo OPENSSL: $with_openssl echo OIDENTD: $enable_oidentd echo PIE: $enable_pie echo TESTS: $enable_tests diff --git a/src/util.c b/src/util.c index d8bf50d..553b746 100644 --- a/src/util.c +++ b/src/util.c @@ -210,8 +210,7 @@ void mylog(int level, char *fmt, ...) #ifdef HAVE_BACKTRACE #include - -void print_trace(void) +void dump_trace(void) { void *array[32]; size_t size; @@ -232,7 +231,7 @@ void fatal(char *fmt, ...) va_end(ap); #ifdef HAVE_BACKTRACE - print_trace(); + dump_trace(); #endif exit(200); From 34a92dedb1609bf816b9e11c7993160a87560463 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 18 Nov 2018 15:07:16 -0500 Subject: [PATCH 11/18] Remove OIDENTD build options. Instead support a runtime option. Note that existing oidentd users will have to add write_oidentd = true in their config to keep existing behavior. --- bip.conf.5 | 4 ++++ configure.ac | 11 ----------- samples/bip.conf | 3 +++ src/bip.c | 15 +++------------ src/bip_main.c | 5 ++--- src/conf.y | 3 ++- src/irc.c | 15 ++++----------- src/irc.h | 4 +--- src/lex.l | 1 + 9 files changed, 20 insertions(+), 41 deletions(-) diff --git a/bip.conf.5 b/bip.conf.5 index d28a2af..68caec2 100644 --- a/bip.conf.5 +++ b/bip.conf.5 @@ -156,6 +156,10 @@ delay = reconn_timer * number of attempts Defines the file where BIP's pid will be stored. BIP checks if this file exists and if the pid is still alive upon startup. If true, BIP refuses to start. +.TP +\fBwrite_oidentd_file\fP (default: \fIfalse\fR) +Must be set to true to overwrite oidentd configs. + .TP \fBoidentd_file\fP (default: \fI/.oidentd.conf\fR) oidentd configuration file (if oidentd enabled). diff --git a/configure.ac b/configure.ac index eca41e8..0f83b85 100644 --- a/configure.ac +++ b/configure.ac @@ -15,16 +15,6 @@ AC_PROG_YACC m4_ifndef([PKG_PROG_PKG_CONFIG], [m4_fatal([Please install pkg-config.])]) PKG_PROG_PKG_CONFIG -AC_ARG_ENABLE([oidentd], AS_HELP_STRING([--enable-oidentd], - [Enable oidentd support (bip overwrites ~/.oidentd.conf with this on!)])) - -AM_CONDITIONAL(OIDENTD, test x$enable_identd = xyes) -AS_IF([test "x$enable_oidentd" = "xyes"], [ - AC_DEFINE([HAVE_OIDENTD], [], [Have bip edit ~/.oidentd.conf]) -], [ - enable_oidentd=no -]) - PKG_CHECK_MODULES(OPENSSL, [libssl >= 0.9.8 libcrypto >= 0.9.8], [with_openssl=yes], [with_openssl=no]) AC_CACHE_CHECK([whether $CC accepts PIE flags], [ap_cv_cc_pie], [ @@ -62,6 +52,5 @@ AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT echo OPENSSL: $with_openssl -echo OIDENTD: $enable_oidentd echo PIE: $enable_pie echo TESTS: $enable_tests diff --git a/samples/bip.conf b/samples/bip.conf index cab74f1..4ca444d 100644 --- a/samples/bip.conf +++ b/samples/bip.conf @@ -43,6 +43,9 @@ # Define where the pidfile should be stored. Defaults to /bip.pid. #pid_file=""; +# Defaults to false, whether to write oidentd.conf files (see below). +#write_oidentd = true; + # Defaults to /.oidentd.conf #oidentd_file=""; diff --git a/src/bip.c b/src/bip.c index 8552fdf..8363d78 100644 --- a/src/bip.c +++ b/src/bip.c @@ -69,10 +69,6 @@ void adm_list_connections(struct link_client *ic, struct bipuser *bu); void free_conf(list_t *l); -#ifdef HAVE_OIDENTD -#define OIDENTD_FILENAME ".oidentd.conf" -#endif - static void hash_binary(char *hex, unsigned char **password, unsigned int *seed) { unsigned char *md5; @@ -981,17 +977,12 @@ int fireup(bip_t *bip, FILE *conf) case LEX_PID_FILE: MOVE_STRING(conf_pid_file, t->pdata); break; - -#ifdef HAVE_OIDENTD + case LEX_WRITE_OIDENTD: + bip->write_oidentd = t->ndata; + break; case LEX_OIDENTD_FILE: MOVE_STRING(bip->oidentdpath, t->pdata); break; -#else - case LEX_OIDENTD_FILE: - mylog(LOG_WARN, "Found oidentd option whereas bip is " - "not built with oidentd support."); - break; -#endif case LEX_ALWAYS_BACKLOG: hds.always_backlog = t->ndata; break; diff --git a/src/bip_main.c b/src/bip_main.c index 5c7fa1f..c1d0d00 100644 --- a/src/bip_main.c +++ b/src/bip_main.c @@ -33,6 +33,7 @@ #include "defaults.h" #define S_CONF "bip.conf" +#define OIDENTD_FILENAME ".oidentd.conf" extern int sighup; extern char *conf_log_root; @@ -217,7 +218,6 @@ int main(int argc, char **argv) strcat(conf_biphome, "/.bip"); } -#ifdef HAVE_OIDENTD if (!bip.oidentdpath) { bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1 + strlen(OIDENTD_FILENAME) + 1); @@ -225,7 +225,6 @@ int main(int argc, char **argv) strcat(bip.oidentdpath, "/"); strcat(bip.oidentdpath, OIDENTD_FILENAME); } -#endif if (!confpath) { confpath = bip_malloc(strlen(conf_biphome) + 1 + @@ -236,7 +235,7 @@ int main(int argc, char **argv) } conf = fopen(confpath, "r"); if (!conf) - fatal("config file not found"); + fatal("config file not found (%s)", confpath); r = fireup(&bip, conf); fclose(conf); diff --git a/src/conf.y b/src/conf.y index 11cc50d..29ef504 100644 --- a/src/conf.y +++ b/src/conf.y @@ -68,7 +68,7 @@ struct tuple *tuple_l_new(int type, void *p) %} -%token LEX_IP LEX_EQ LEX_PORT LEX_CSS LEX_SEMICOLON LEX_CONNECTION LEX_NETWORK LEX_LBRA LEX_RBRA LEX_USER LEX_NAME LEX_NICK LEX_SERVER LEX_PASSWORD LEX_SRCIP LEX_HOST LEX_VHOST LEX_SOURCE_PORT LEX_NONE LEX_COMMENT LEX_BUNCH LEX_REALNAME LEX_SSL LEX_SSL_CHECK_MODE LEX_SSL_CHECK_STORE LEX_SSL_CLIENT_CERTFILE LEX_CIPHERS LEX_CSS_CIPHERS LEX_DEFAULT_CIPHERS LEX_DH_PARAM LEX_CHANNEL LEX_KEY LEX_LOG_ROOT LEX_LOG_FORMAT LEX_LOG_LEVEL LEX_BACKLOG_LINES LEX_BACKLOG_NO_TIMESTAMP LEX_BACKLOG LEX_LOG LEX_LOG_SYSTEM LEX_LOG_SYNC_INTERVAL LEX_FOLLOW_NICK LEX_ON_CONNECT_SEND LEX_AWAY_NICK LEX_PID_FILE LEX_OIDENTD_FILE LEX_IGN_FIRST_NICK LEX_ALWAYS_BACKLOG LEX_BLRESET_ON_TALK LEX_BLRESET_CONNECTION LEX_DEFAULT_USER LEX_DEFAULT_NICK LEX_DEFAULT_REALNAME LEX_NO_CLIENT_AWAY_MSG LEX_BL_MSG_ONLY LEX_ADMIN LEX_BIP_USE_NOTICE LEX_CSS_PEM LEX_AUTOJOIN_ON_KICK LEX_IGNORE_CAPAB LEX_RECONN_TIMER +%token LEX_IP LEX_EQ LEX_PORT LEX_CSS LEX_SEMICOLON LEX_CONNECTION LEX_NETWORK LEX_LBRA LEX_RBRA LEX_USER LEX_NAME LEX_NICK LEX_SERVER LEX_PASSWORD LEX_SRCIP LEX_HOST LEX_VHOST LEX_SOURCE_PORT LEX_NONE LEX_COMMENT LEX_BUNCH LEX_REALNAME LEX_SSL LEX_SSL_CHECK_MODE LEX_SSL_CHECK_STORE LEX_SSL_CLIENT_CERTFILE LEX_CIPHERS LEX_CSS_CIPHERS LEX_DEFAULT_CIPHERS LEX_DH_PARAM LEX_CHANNEL LEX_KEY LEX_LOG_ROOT LEX_LOG_FORMAT LEX_LOG_LEVEL LEX_BACKLOG_LINES LEX_BACKLOG_NO_TIMESTAMP LEX_BACKLOG LEX_LOG LEX_LOG_SYSTEM LEX_LOG_SYNC_INTERVAL LEX_FOLLOW_NICK LEX_ON_CONNECT_SEND LEX_AWAY_NICK LEX_PID_FILE LEX_WRITE_OIDENTD LEX_OIDENTD_FILE LEX_IGN_FIRST_NICK LEX_ALWAYS_BACKLOG LEX_BLRESET_ON_TALK LEX_BLRESET_CONNECTION LEX_DEFAULT_USER LEX_DEFAULT_NICK LEX_DEFAULT_REALNAME LEX_NO_CLIENT_AWAY_MSG LEX_BL_MSG_ONLY LEX_ADMIN LEX_BIP_USE_NOTICE LEX_CSS_PEM LEX_AUTOJOIN_ON_KICK LEX_IGNORE_CAPAB LEX_RECONN_TIMER %union { int number; @@ -107,6 +107,7 @@ command: | LEX_LOG_SYNC_INTERVAL LEX_EQ LEX_INT { $$ = tuple_i_new( LEX_LOG_SYNC_INTERVAL, $3); } | LEX_PID_FILE LEX_EQ LEX_STRING { $$ = tuple_s_new(LEX_PID_FILE, $3); } + | LEX_WRITE_OIDENTD LEX_EQ LEX_BOOL { $$ = tuple_i_new(LEX_WRITE_OIDENTD, $3); } | LEX_OIDENTD_FILE LEX_EQ LEX_STRING { $$ = tuple_s_new(LEX_OIDENTD_FILE, $3); } /* deprecated */ | LEX_BACKLOG_LINES LEX_EQ LEX_INT { diff --git a/src/irc.c b/src/irc.c index 7a1cbbf..7a51c9e 100644 --- a/src/irc.c +++ b/src/irc.c @@ -54,10 +54,7 @@ static void server_init_modes(struct link_server *s); static int bip_get_index(const char* str, char car); static int bip_fls(int v); -#ifdef HAVE_OIDENTD -#define OIDENTD_FILENAME ".oidentd.conf" void oidentd_dump(bip_t *bip); -#endif void irc_client_free(struct link_client *cli); extern int conf_log_sync_interval; @@ -2194,9 +2191,7 @@ connection_t *irc_server_connect(struct link *link) conn->user_data = ls; list_add_last(&_bip->conn_list, conn); -#ifdef HAVE_OIDENTD oidentd_dump(_bip); -#endif irc_server_startup(ls); return conn; } @@ -2237,15 +2232,16 @@ void irc_server_shutdown(struct link_server *s) LINK(s)->prev_nick = bip_strdup(s->nick); } - -#ifdef HAVE_OIDENTD - #define BIP_OIDENTD_START "## AUTOGENERATED BY BIP. DO NOT EDIT ##\n" #define BIP_OIDENTD_END "## END OF AUTOGENERATED STUFF ##\n" #define BIP_OIDENTD_END_LENGTH strlen(BIP_OIDENTD_END) void oidentd_dump(bip_t *bip) { + mylog(LOG_ERROR, "%d %s", bip->write_oidentd, bip->oidentdpath); + if (!bip->write_oidentd || bip->oidentdpath == NULL) { + return; + } list_iterator_t it; FILE *f; char *bipstart = NULL, *bipend = NULL; @@ -2352,7 +2348,6 @@ void oidentd_dump(bip_t *bip) clean_oidentd: fclose(f); } -#endif void timeout_clean_who_counts(list_t *conns) { @@ -2559,10 +2554,8 @@ void irc_main(bip_t *bip) int nc; /* Da main loop */ list_t *ready = wait_event(&bip->conn_list, &timeleft, &nc); -#ifdef HAVE_OIDENTD if (nc) oidentd_dump(bip); -#endif while ((conn = list_remove_first(ready))) bip_on_event(bip, conn); list_free(ready); diff --git a/src/irc.h b/src/irc.h index bc590a1..7969072 100644 --- a/src/irc.h +++ b/src/irc.h @@ -250,10 +250,8 @@ typedef struct bip { hash_t users; list_t errors; struct link_client *reloading_client; - -#ifdef HAVE_OIDENTD char *oidentdpath; -#endif + int write_oidentd; } bip_t; void bip_init(bip_t *bip); diff --git a/src/lex.l b/src/lex.l index 1a3680a..45db3e5 100644 --- a/src/lex.l +++ b/src/lex.l @@ -108,6 +108,7 @@ list_t *parse_conf(FILE *file, int *err) "on_connect_send" { return LEX_ON_CONNECT_SEND; } "no_client_away_msg" { return LEX_NO_CLIENT_AWAY_MSG; } "pid_file" { return LEX_PID_FILE; } +"write_oidentd" { return LEX_WRITE_OIDENTD; } "oidentd_file" { return LEX_OIDENTD_FILE; } "bip_use_notice" { return LEX_BIP_USE_NOTICE; } "client_side_ssl_pem" { return LEX_CSS_PEM; } From 2bf967bacc58192c92604462b7a5ee704b98a605 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 18 Nov 2018 15:37:46 -0500 Subject: [PATCH 12/18] Add missing OpenSSL CFLAGS/LDFLAGs to build. Those were removed by mistake in the previous autotool refactor. --- configure.ac | 6 +++++- src/Makefile.am | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 0f83b85..cea6068 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,11 @@ AC_PROG_YACC m4_ifndef([PKG_PROG_PKG_CONFIG], [m4_fatal([Please install pkg-config.])]) PKG_PROG_PKG_CONFIG -PKG_CHECK_MODULES(OPENSSL, [libssl >= 0.9.8 libcrypto >= 0.9.8], [with_openssl=yes], [with_openssl=no]) +PKG_CHECK_MODULES(OPENSSL, [libssl >= 0.9.8 libcrypto >= 0.9.8], [ + with_openssl=yes + AC_DEFINE([HAVE_LIBSSL], [1], + [Build SSL support]) + ], [ with_openssl=no ]) AC_CACHE_CHECK([whether $CC accepts PIE flags], [ap_cv_cc_pie], [ save_CFLAGS=$CFLAGS diff --git a/src/Makefile.am b/src/Makefile.am index 04b6ee7..573b228 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,10 +12,13 @@ libbip_a_SOURCES = conf.y lex.l \ tuple.h \ util.c util.h +libbip_a_CFLAGS = ${OPENSSL_CFLAGS} + bin_PROGRAMS = bip bipmkpw bip_SOURCES = bip_main.c -bip_LDADD = libbip.a +bip_LDADD = libbip.a ${OPENSSL_LIBS} + bipmkpw_SOURCES = bipmkpw.c md5.c util.c AM_YFLAGS= -d From ba5cef017cdd5cb579589c7c0f3f8b8938532a62 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Fri, 30 Nov 2018 09:00:51 -0500 Subject: [PATCH 13/18] Fix test automake file to link openssl. --- tests/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 1d781a8..edb10e5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ TESTS = check_line check_PROGRAMS = check_line check_line_SOURCES = check_line.c $(top_builddir)/src/line.h -check_line_CFLAGS = @CHECK_CFLAGS@ -check_line_LDADD = $(top_builddir)/src/libbip.a @CHECK_LIBS@ +check_line_CFLAGS = @CHECK_CFLAGS@ $(OPENSSL_CFLAGS) +check_line_LDADD = $(top_builddir)/src/libbip.a @CHECK_LIBS@ $(OPENSSL_LIBS) From 513a6582ad2cb395e40b5597b38fcdbb8751b695 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 9 Dec 2018 14:04:43 -0500 Subject: [PATCH 14/18] Add CFLAGS needed for openssl. Otherwise building fails in platforms with esoteric openssl locations. --- src/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 573b228..161fa56 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,9 +17,11 @@ libbip_a_CFLAGS = ${OPENSSL_CFLAGS} bin_PROGRAMS = bip bipmkpw bip_SOURCES = bip_main.c +bip_CFLAGS = ${OPENSSL_CFLAGS} bip_LDADD = libbip.a ${OPENSSL_LIBS} bipmkpw_SOURCES = bipmkpw.c md5.c util.c +bipmkpw_CFLAGS = ${OPENSSL_CFLAGS} AM_YFLAGS= -d BUILT_SOURCES = conf.c conf.h lex.c From caf979a4c5b0205068b61ba6628bb679823068fd Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 9 Dec 2018 14:27:59 -0500 Subject: [PATCH 15/18] Close descriptor when SSL reports a system error. Avoids leaking fd when connections are closed abruptly. --- src/connection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connection.c b/src/connection.c index a322ab4..040bfeb 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1493,7 +1493,8 @@ static int SSLize(connection_t *cn, int *nc) } if (err2 == SSL_ERROR_SYSCALL) { - /* socked died */ + mylog(LOG_ERROR, "Error with socket during ssl handshake."); + connection_close(cn); cn->connected = CONN_ERROR; return 1; } From 936b76690596a37fa1c4143f1ca382ccfa974770 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 9 Dec 2018 15:08:58 -0500 Subject: [PATCH 16/18] Make the tests subdirectory optional. Otherwise build breaks when check is not installed. --- Makefile.am | 5 ++++- configure.ac | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 12442b8..34de37a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,7 @@ -SUBDIRS = src . tests +if COND_WANT_TESTS + MAYBE_TESTS = tests +endif +SUBDIRS = src . $(MAYBE_TESTS) dist_man_MANS = bip.1 bip.conf.5 bipmkpw.1 diff --git a/configure.ac b/configure.ac index cea6068..2faf491 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,7 @@ PKG_CHECK_MODULES([CHECK], [check >= 0.9.6], [ AC_CONFIG_FILES([tests/Makefile]) enable_tests=yes ], [ enable_tests=no ]) +AM_CONDITIONAL([COND_WANT_TESTS], [test "$enable_tests" = yes]) AC_CHECK_FUNC(backtrace_symbols_fd, [ AC_DEFINE(HAVE_BACKTRACE, [], [Use glibc backtrace on fatal()]) From e224f067c1d26c067ed80cd9f94377dbbb878933 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 9 Dec 2018 16:06:18 -0500 Subject: [PATCH 17/18] Fix the conditional build of tests again. Per [1], you always output the optional directory Makefile. [1] https://www.gnu.org/software/automake/manual/html_node/Subdirectories-with-AM_005fCONDITIONAL.html#Subdirectories-with-AM_005fCONDITIONAL --- configure.ac | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 2faf491..8821145 100644 --- a/configure.ac +++ b/configure.ac @@ -40,10 +40,7 @@ if test "$ap_cv_cc_pie" = "yes"; then enable_pie=yes fi -PKG_CHECK_MODULES([CHECK], [check >= 0.9.6], [ - AC_CONFIG_FILES([tests/Makefile]) - enable_tests=yes - ], [ enable_tests=no ]) +PKG_CHECK_MODULES([CHECK], [check >= 0.9.6], [enable_tests=yes], [enable_tests=no]) AM_CONDITIONAL([COND_WANT_TESTS], [test "$enable_tests" = yes]) AC_CHECK_FUNC(backtrace_symbols_fd, [ @@ -53,7 +50,7 @@ AC_CHECK_FUNC(backtrace_symbols_fd, [ ]) -AC_CONFIG_FILES([Makefile src/Makefile]) +AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile]) AC_OUTPUT echo OPENSSL: $with_openssl From 02c55a37b2cd9561a57ed3869ca147cbb1644ff3 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Wed, 30 May 2018 03:34:12 +0200 Subject: [PATCH 18/18] add debug log & differentiate error messages --- src/connection.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/connection.c b/src/connection.c index 040bfeb..0dad476 100644 --- a/src/connection.c +++ b/src/connection.c @@ -57,8 +57,8 @@ static void connecting_data_free(struct connecting_data *t) void connection_close(connection_t *cn) { - mylog(LOG_DEBUG, "Connection close asked. FD:%d ", - (long)cn->handle); + mylog(LOG_DEBUG, "Connection close asked. FD:%d (status: %d)", + (long)cn->handle, cn->connected); if (cn->connected != CONN_DISCONN && cn->connected != CONN_ERROR) { cn->connected = CONN_DISCONN; if (close(cn->handle) == -1) @@ -630,7 +630,7 @@ static int check_event_except(fd_set *fds, connection_t *cn) return 0; if (cn_is_in_error(cn)) { - mylog(LOG_ERROR, "Error on fd %d (state %d)", + mylog(LOG_ERROR, "Error on fd %d (except, state %d)", cn->handle, cn->connected); return 1; } @@ -648,7 +648,7 @@ static int check_event_read(fd_set *fds, connection_t *cn) int ret; if (cn_is_in_error(cn)) { - mylog(LOG_ERROR, "Error on fd %d (state %d)", + mylog(LOG_ERROR, "Error on fd %d (read, state %d)", cn->handle, cn->connected); return 1; } @@ -702,7 +702,7 @@ static void connection_connected(connection_t *c) static int check_event_write(fd_set *fds, connection_t *cn, int *nc) { if (cn_is_in_error(cn)) { - mylog(LOG_ERROR, "Error on fd %d (state %d)", + mylog(LOG_ERROR, "Error on fd %d (write, state %d)", cn->handle, cn->connected); return 1; }