Browse Source

* update binaries for use refactored f2b_csocket_*() functions

master
Alex 'AdUser' Z 4 years ago
parent
commit
b3d125634a
  1. 2
      src/CMakeLists.txt
  2. 4
      src/appconfig.c
  3. 1
      src/appconfig.h
  4. 2
      src/client.c
  5. 5
      src/common.h
  6. 12
      src/csocket-test.c
  7. 8
      src/daemon.c

2
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") set(SOURCES "strlcpy.c" "backend-test.c" "log.c" "config.c" "backend.c")
add_executable("f2b-backend-test" ${SOURCES}) 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}) add_executable("f2b-csocket-test" ${SOURCES})
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")

4
src/appconfig.c

@ -21,7 +21,6 @@ f2b_appconfig_t appconfig = {
.logdest = "file", .logdest = "file",
.config_path = "/etc/f2b/f2b.conf", .config_path = "/etc/f2b/f2b.conf",
.logfile_path = "/var/log/f2b.log", .logfile_path = "/var/log/f2b.log",
.csocket_path = DEFAULT_CSOCKET_PATH,
.pidfile_path = DEFAULT_PIDFILE_PATH, .pidfile_path = DEFAULT_PIDFILE_PATH,
.statedir_path = DEFAULT_STATEDIR_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) if ((pa = f2b_config_param_find(section->param, "pidfile")) != NULL)
strlcpy(appconfig.pidfile_path, pa->value, sizeof(appconfig.pidfile_path)); 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) if ((pa = f2b_config_param_find(section->param, "statedir")) != NULL)
strlcpy(appconfig.statedir_path, pa->value, sizeof(appconfig.statedir_path)); strlcpy(appconfig.statedir_path, pa->value, sizeof(appconfig.statedir_path));

1
src/appconfig.h

@ -16,7 +16,6 @@ typedef struct f2b_appconfig_t {
char logdest[CONFIG_KEY_MAX]; char logdest[CONFIG_KEY_MAX];
char config_path[PATH_MAX]; char config_path[PATH_MAX];
char logfile_path[PATH_MAX]; char logfile_path[PATH_MAX];
char csocket_path[PATH_MAX];
char pidfile_path[PATH_MAX]; char pidfile_path[PATH_MAX];
char statedir_path[PATH_MAX]; char statedir_path[PATH_MAX];
} f2b_appconfig_t; } f2b_appconfig_t;

2
src/client.c

@ -15,6 +15,8 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <signal.h> #include <signal.h>
#define DEFAULT_CSOCKET_PATH "/var/run/f2b.sock"
#ifdef WITH_READLINE #ifdef WITH_READLINE
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>

5
src/common.h

@ -36,10 +36,7 @@
* Self-descriptive * Self-descriptive
*/ */
#define DEFAULT_PIDFILE_PATH "/var/run/f2b.pid" #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 * Default path of directory to store ip states for jails
*/ */

12
src/csocket-test.c

@ -1,4 +1,5 @@
#include "common.h" #include "common.h"
#include "config.h"
#include "buf.h" #include "buf.h"
#include "log.h" #include "log.h"
#include "commands.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) { int main(int argc, const char **argv) {
f2b_config_t config;
f2b_csock_t *csock = NULL; f2b_csock_t *csock = NULL;
if (argc < 2) { if (argc < 2) {
puts("Usage: csocket-test <path>"); puts("Usage: csocket-test <csocket.conf>");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
f2b_log_set_level("debug"); f2b_log_set_level("debug");
f2b_log_to_stderr(); 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()"); perror("f2b_csocket_create()");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

8
src/daemon.c

@ -67,7 +67,7 @@ static f2b_csock_t *csock = NULL;
#ifndef WITH_CSOCKET #ifndef WITH_CSOCKET
/* add stubs to reduce #ifdef count */ /* add stubs to reduce #ifdef count */
f2b_csock_t * f2b_csock_t *
f2b_csocket_create (const char *path) { f2b_csocket_create (f2b_config_section_t *config) {
UNUSED(path); UNUSED(path);
f2b_log_msg(log_warn, "control socket support was disabled at compile-time"); f2b_log_msg(log_warn, "control socket support was disabled at compile-time");
return NULL; 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); f2b_buf_append(res, buf, len);
len = snprintf(buf, sizeof(buf), "pid: %u\npidfile: %s\n", getpid(), appconfig.pidfile_path); len = snprintf(buf, sizeof(buf), "pid: %u\npidfile: %s\n", getpid(), appconfig.pidfile_path);
f2b_buf_append(res, buf, len); 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); len = snprintf(buf, sizeof(buf), "statedir: %s\n", appconfig.statedir_path);
f2b_buf_append(res, buf, len); f2b_buf_append(res, buf, len);
f2b_buf_append(res, "jails:\n", 0); f2b_buf_append(res, "jails:\n", 0);
@ -338,8 +336,8 @@ int main(int argc, char *argv[]) {
} }
} }
if (appconfig.csocket_path[0] != '\0') { if (config.csocket) {
csock = f2b_csocket_create(appconfig.csocket_path); csock = f2b_csocket_create(config.csocket);
} }
if (config.defaults) if (config.defaults)

Loading…
Cancel
Save