aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJulien Dessaux2019-03-14 23:34:55 +0100
committerJulien Dessaux2019-03-18 11:33:03 +0100
commit1b9a3e8c4bdb99f7713958a3f284e06438b95bb1 (patch)
treeb6f44d742dd3631ac9fb0ba624cba90e40c40993 /common
parentAdd cmake installation rules along with cpack entries. Made cmake_build_type ... (diff)
downloadbastion-1b9a3e8c4bdb99f7713958a3f284e06438b95bb1.tar.gz
bastion-1b9a3e8c4bdb99f7713958a3f284e06438b95bb1.tar.bz2
bastion-1b9a3e8c4bdb99f7713958a3f284e06438b95bb1.zip
Made all settings customisable through a config file.
Diffstat (limited to 'common')
-rw-r--r--common/config.c86
-rw-r--r--common/config.h.in28
2 files changed, 107 insertions, 7 deletions
diff --git a/common/config.c b/common/config.c
new file mode 100644
index 0000000..e8196ce
--- /dev/null
+++ b/common/config.c
@@ -0,0 +1,86 @@
+#include <libconfig.h>
+#include <stdlib.h>
+
+#include "config.h"
+
+config_t * config = NULL;
+
+char // returns 0 if ok, greater than 0 otherwise
+config_load(void)
+{
+ config = malloc(sizeof(config_t));
+ config_init(config);
+ config_set_tab_width(config, 4);
+ if (config_read_file(config, CONFIG_PATH) != CONFIG_TRUE) {
+ switch(config_error_type(config)) {
+ case CONFIG_ERR_NONE:
+ fprintf(stderr, "Configuration read error with none type reported... This shouldn't happen!\n");
+ break;
+ case CONFIG_ERR_FILE_IO:
+ fprintf(stderr, "Configuration I/O error, the most common cause is a file not found at %s\n", CONFIG_PATH);
+ break;
+ case CONFIG_ERR_PARSE:
+ fprintf(stderr, "Configuration parse error\n");
+ break;
+ }
+ fprintf(stderr, "Configuration read error occured at %s:%d %s\n", config_error_file(config), config_error_line(config), config_error_text(config));
+ return 1;
+ }
+ return 0;
+}
+
+int config_get_port(void)
+{
+ int port;
+ if (config_lookup_int(config, "port", &port) != CONFIG_TRUE) {
+ return DEFAULT_PORT;
+ }
+ return port;
+}
+
+const char * config_get_key_dsa(void)
+{
+ const char * key;
+ if (config_lookup_string(config, "keys.dsa", &key) != CONFIG_TRUE) {
+ return DEFAULT_DSAKEY_PATH;
+ }
+ return key;
+}
+
+const char * config_get_key_rsa(void)
+{
+ const char * key;
+ if (config_lookup_string(config, "keys.rsa", &key) != CONFIG_TRUE) {
+ return DEFAULT_RSAKEY_PATH;
+ }
+ return key;
+}
+
+const char * config_get_key_ecdsa(void)
+{
+ const char * key;
+ if (config_lookup_string(config, "keys.ecdsa", &key) != CONFIG_TRUE) {
+ return DEFAULT_ECDSAKEY_PATH;
+ }
+ return key;
+}
+
+#ifdef SESSION_RECORDING
+const char * config_get_session_recording_path(void)
+{
+ const char * key;
+ if (config_lookup_string(config, "session_recording.path", &key) != CONFIG_TRUE) {
+ return DEFAULT_SESSION_RECORDING_PATH;
+ }
+ return key;
+}
+#endif
+
+void config_clean(void)
+{
+ if (config != NULL) {
+ config_destroy(config);
+ free(config);
+ config = NULL;
+ }
+}
diff --git a/common/config.h.in b/common/config.h.in
index 1263c7c..189e725 100644
--- a/common/config.h.in
+++ b/common/config.h.in
@@ -1,21 +1,35 @@
#ifndef COMMON_CONFIG_H_
#define COMMON_CONFIG_H_
-#define LISTEN_PORT 2222
+#define CONFIG_PATH "@CMAKE_INSTALL_PREFIX@/etc/bastion/bastion.conf"
+
#define MAX_HOSTNAME_LENGTH 64
#define MAX_USERNAME_LENGTH 64
-#define DSAKEY_PATH "@CMAKE_INSTALL_PREFIX@/etc/ssh_host_dsa_key"
-#define RSAKEY_PATH "@CMAKE_INSTALL_PREFIX@/etc/ssh_host_rsa_key"
-#define ECDSAKEY_PATH "@CMAKE_INSTALL_PREFIX@/etc/ssh_host_ecdsa_key"
+#define DEFAULT_PORT 2222
+#define DEFAULT_DSAKEY_PATH "@CMAKE_INSTALL_PREFIX@/etc/bastion/ssh_host_dsa_key"
+#define DEFAULT_RSAKEY_PATH "@CMAKE_INSTALL_PREFIX@/etc/bastion/ssh_host_rsa_key"
+#define DEFAULT_ECDSAKEY_PATH "@CMAKE_INSTALL_PREFIX@/etc/bastion/ssh_host_ecdsa_key"
#define MYSQL_HOST "localhost"
#define MYSQL_USER "sshportal"
#define MYSQL_PASS "graou"
#define MYSQL_DB "sshportal"
-#define LOG_FILENAME_FORMAT "@CMAKE_INSTALL_PREFIX@/var/log/$d/$h/$u/$i.gz" // $d : date in iso format, $h : hostname, $u : username : $i session id
-#define LOG_FILENAME_MAX_LEN 255
-#define LOG_DIRECTORY_MODE S_IRUSR | S_IWUSR | S_IXUSR
+#ifdef SESSION_RECORDING
+#define DEFAULT_SESSION_RECORDING_PATH "@CMAKE_INSTALL_PREFIX@/var/log/bastion/$d/$h/$u/$i.gz"
+#define SESSION_RECORDING_FILENAME_MAX_LEN 255
+#define SESSION_RECORDING_DIRECTORY_MODE S_IRUSR | S_IWUSR | S_IXUSR
+#endif
+
+char config_load(void);
+int config_get_port(void);
+const char * config_get_key_dsa(void);
+const char * config_get_key_rsa(void);
+const char * config_get_key_ecdsa(void);
+#ifdef SESSION_RECORDING
+const char * config_get_session_recording_path(void);
+#endif
+void config_clean(void);
#endif