From b3d125634a7117546d45a03cc1c928cba47c6b8a Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 23 Mar 2021 17:05:22 +1000 Subject: [PATCH] * update binaries for use refactored f2b_csocket_*() functions --- src/CMakeLists.txt | 2 +- src/appconfig.c | 4 ---- src/appconfig.h | 1 - src/client.c | 2 ++ src/common.h | 5 +---- src/csocket-test.c | 12 ++++++++++-- src/daemon.c | 8 +++----- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25f8d57..c4b6727 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,7 @@ add_executable("f2b-filter-test" ${SOURCES}) set(SOURCES "strlcpy.c" "backend-test.c" "log.c" "config.c" "backend.c") add_executable("f2b-backend-test" ${SOURCES}) -set(SOURCES "strlcpy.c" "csocket-test.c" "log.c" "buf.c" "commands.c" "csocket.c") +set(SOURCES "strlcpy.c" "csocket-test.c" "log.c" "buf.c" "config.c" "commands.c" "csocket.c") add_executable("f2b-csocket-test" ${SOURCES}) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") diff --git a/src/appconfig.c b/src/appconfig.c index f21a033..12e1e21 100644 --- a/src/appconfig.c +++ b/src/appconfig.c @@ -21,7 +21,6 @@ f2b_appconfig_t appconfig = { .logdest = "file", .config_path = "/etc/f2b/f2b.conf", .logfile_path = "/var/log/f2b.log", - .csocket_path = DEFAULT_CSOCKET_PATH, .pidfile_path = DEFAULT_PIDFILE_PATH, .statedir_path = DEFAULT_STATEDIR_PATH, }; @@ -58,9 +57,6 @@ f2b_appconfig_update(f2b_config_section_t *section) { if ((pa = f2b_config_param_find(section->param, "pidfile")) != NULL) strlcpy(appconfig.pidfile_path, pa->value, sizeof(appconfig.pidfile_path)); - if ((pa = f2b_config_param_find(section->param, "csocket")) != NULL) - strlcpy(appconfig.csocket_path, pa->value, sizeof(appconfig.csocket_path)); - if ((pa = f2b_config_param_find(section->param, "statedir")) != NULL) strlcpy(appconfig.statedir_path, pa->value, sizeof(appconfig.statedir_path)); diff --git a/src/appconfig.h b/src/appconfig.h index 2dd7918..55842e3 100644 --- a/src/appconfig.h +++ b/src/appconfig.h @@ -16,7 +16,6 @@ typedef struct f2b_appconfig_t { char logdest[CONFIG_KEY_MAX]; char config_path[PATH_MAX]; char logfile_path[PATH_MAX]; - char csocket_path[PATH_MAX]; char pidfile_path[PATH_MAX]; char statedir_path[PATH_MAX]; } f2b_appconfig_t; diff --git a/src/client.c b/src/client.c index 66c5428..becc013 100644 --- a/src/client.c +++ b/src/client.c @@ -15,6 +15,8 @@ #include #include +#define DEFAULT_CSOCKET_PATH "/var/run/f2b.sock" + #ifdef WITH_READLINE #include #include diff --git a/src/common.h b/src/common.h index 1bb16b9..ec57036 100644 --- a/src/common.h +++ b/src/common.h @@ -36,10 +36,7 @@ * Self-descriptive */ #define DEFAULT_PIDFILE_PATH "/var/run/f2b.pid" -/** - * Default path of unix control socket - */ -#define DEFAULT_CSOCKET_PATH "/var/run/f2b.sock" + /** * Default path of directory to store ip states for jails */ diff --git a/src/csocket-test.c b/src/csocket-test.c index 9c1fad7..8837e53 100644 --- a/src/csocket-test.c +++ b/src/csocket-test.c @@ -1,4 +1,5 @@ #include "common.h" +#include "config.h" #include "buf.h" #include "log.h" #include "commands.h" @@ -19,17 +20,24 @@ cmd_handler(const f2b_cmd_t *cmd, f2b_buf_t *res) { } int main(int argc, const char **argv) { + f2b_config_t config; f2b_csock_t *csock = NULL; if (argc < 2) { - puts("Usage: csocket-test "); + puts("Usage: csocket-test "); exit(EXIT_FAILURE); } f2b_log_set_level("debug"); f2b_log_to_stderr(); - if ((csock = f2b_csocket_create(argv[1])) == NULL) { + memset(&config, 0x0, sizeof(config)); + if (!f2b_config_load(&config, argv[1], false)) { + f2b_log_msg(log_fatal, "can't load config"); + return EXIT_FAILURE; + } + + if ((csock = f2b_csocket_create(config.csocket)) == NULL) { perror("f2b_csocket_create()"); exit(EXIT_FAILURE); } diff --git a/src/daemon.c b/src/daemon.c index 7cc4ea3..5031e92 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -67,7 +67,7 @@ static f2b_csock_t *csock = NULL; #ifndef WITH_CSOCKET /* add stubs to reduce #ifdef count */ f2b_csock_t * -f2b_csocket_create (const char *path) { +f2b_csocket_create (f2b_config_section_t *config) { UNUSED(path); f2b_log_msg(log_warn, "control socket support was disabled at compile-time"); return NULL; @@ -124,8 +124,6 @@ f2b_csocket_cmd_process(const f2b_cmd_t *cmd, f2b_buf_t *res) { f2b_buf_append(res, buf, len); len = snprintf(buf, sizeof(buf), "pid: %u\npidfile: %s\n", getpid(), appconfig.pidfile_path); f2b_buf_append(res, buf, len); - len = snprintf(buf, sizeof(buf), "csocket: %s\n", appconfig.csocket_path); - f2b_buf_append(res, buf, len); len = snprintf(buf, sizeof(buf), "statedir: %s\n", appconfig.statedir_path); f2b_buf_append(res, buf, len); f2b_buf_append(res, "jails:\n", 0); @@ -338,8 +336,8 @@ int main(int argc, char *argv[]) { } } - if (appconfig.csocket_path[0] != '\0') { - csock = f2b_csocket_create(appconfig.csocket_path); + if (config.csocket) { + csock = f2b_csocket_create(config.csocket); } if (config.defaults)