From 214d2f2f315a1ed58fce00e398108b8da4444bdf Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Wed, 9 Jan 2013 22:24:34 +0100 Subject: [PATCH] Harden the build system. Fix configuration error processing. --- config.c | 65 +++++++++++++++++++++++++++++----------------- jsonbot.c | 15 +++++++---- siahs.c | 4 --- siahsd-init-script | 55 +++++++++++++++++++++++++++++++++++++++ wscript | 27 ++++++++++--------- 5 files changed, 121 insertions(+), 45 deletions(-) create mode 100755 siahsd-init-script diff --git a/config.c b/config.c index 8cf2cdc..de59a81 100644 --- a/config.c +++ b/config.c @@ -115,21 +115,47 @@ STATUS read_configuration_file(TALLOC_CTX *mem_ctx) if (!g_key_file_load_from_file (conf->keyfile, CONFIGFILE, 0, &error)) { g_error (error->message); + g_error_free(error); return ST_CONFIGURATION_ERROR; } buf = g_key_file_get_string(conf->keyfile, "siahsd", "event handlers", &error); if (error) { - fprintf(stderr, "No log file supplied in the configuration.\n"); + fprintf(stderr, "No event handler supplied in the configuration.\n"); + g_error_free(error); return ST_CONFIGURATION_ERROR; } - DEBUG(0, "%s\n", buf); + conf->log_file = g_key_file_get_string(conf->keyfile, "siahsd", "log file", &error); + if (error) { + fprintf(stderr, "No log file supplied in the configuration.\n"); + g_error_free(error); + return ST_CONFIGURATION_ERROR; + } + conf->log_level = g_key_file_get_integer(conf->keyfile, "siahsd", "log level", &error); + if (error) { + fprintf(stderr, "No log level supplied in the configuration.\n"); + g_error_free(error); + return ST_CONFIGURATION_ERROR; + } + conf->pid_file = g_key_file_get_string(conf->keyfile, "siahsd", "pid file", &error); + if (error) { + fprintf(stderr, "No pid file supplied in the configuration.\n"); + g_error_free(error); + return ST_CONFIGURATION_ERROR; + } + + conf->foreground = g_key_file_get_boolean(conf->keyfile, "siahsd", "foreground", &error); + if (error) { + conf->foreground = false; + g_error_free(error); + error = NULL; + } + /* Initialize the required event handler backends */ ptr = strtok(buf, " "); if (ptr != NULL) { do { - DEBUG(0, "%s\n", ptr); if (strcmp(ptr, "database") == 0) { database_init(); } else if (strcmp(ptr, "jsonbot") == 0) { @@ -138,32 +164,23 @@ STATUS read_configuration_file(TALLOC_CTX *mem_ctx) } while((ptr = strtok(NULL, " ")) != NULL); } - conf->log_file = g_key_file_get_string(conf->keyfile, "siahsd", "log file", &error); - if (error) { - fprintf(stderr, "No log file supplied in the configuration.\n"); - return ST_CONFIGURATION_ERROR; - } - conf->log_level = g_key_file_get_integer(conf->keyfile, "siahsd", "log level", &error); - if (error) { - fprintf(stderr, "No log level supplied in the configuration.\n"); - return ST_CONFIGURATION_ERROR; - } - conf->pid_file = g_key_file_get_string(conf->keyfile, "siahsd", "pid file", &error); - if (error) { - fprintf(stderr, "No pid file supplied in the configuration.\n"); - return ST_CONFIGURATION_ERROR; - } - - conf->foreground = g_key_file_get_boolean(conf->keyfile, "siahsd", "foreground", &error); - if (error) { - conf->foreground = false; - } - /* Optional parameters are protocol-specific */ /* FIXME Warn the user when these aren't configured */ conf->siahs_port = g_key_file_get_integer(conf->keyfile, "siahs", "port", &error); + if (error) { + g_error_free(error); + error = NULL; + } conf->secip_port = g_key_file_get_integer(conf->keyfile, "secip", "port", &error); + if (error) { + g_error_free(error); + error = NULL; + } conf->rsa_key_file = g_key_file_get_string(conf->keyfile, "secip", "rsa key file", &error); + if (error) { + g_error_free(error); + error = NULL; + } return ST_OK; } diff --git a/jsonbot.c b/jsonbot.c index ce11fa1..c22cdd7 100644 --- a/jsonbot.c +++ b/jsonbot.c @@ -33,6 +33,11 @@ STATUS jsonbot_notify(TALLOC_CTX *mem_ctx, const char *prom, const char *code, c conf = get_conf(); + /* Ignore test reports */ + if (strncmp(code, "RP", 2) == 0) { + return ST_OK; + } + aes_set_encrypt_key(&aes, strlen(conf->jsonbot_aeskey), (uint8_t *) conf->jsonbot_aeskey); @@ -84,27 +89,27 @@ STATUS jsonbot_init(void) { conf->jsonbot_address = g_key_file_get_string(conf->keyfile, "jsonbot", "address", &error); if (error) { - fprintf(stderr, "No jsonbot address supplied in the configuration.\n"); + fprintf(stderr, "Error parsing jsonbot address: (%d) %s.\n", error->code, error->message); return ST_CONFIGURATION_ERROR; } conf->jsonbot_port = g_key_file_get_integer(conf->keyfile, "jsonbot", "port", &error); if (error) { - fprintf(stderr, "No jsonbot port supplied in the configuration.\n"); + fprintf(stderr, "Error parsing jsonbot port: (%d) %s.\n", error->code, error->message); return ST_CONFIGURATION_ERROR; } conf->jsonbot_aeskey = g_key_file_get_string(conf->keyfile, "jsonbot", "aes key", &error); if (error) { - fprintf(stderr, "No jsonbot aes key supplied in the configuration.\n"); + fprintf(stderr, "Error parsing jsonbot aes key: (%d) %s.\n", error->code, error->message); return ST_CONFIGURATION_ERROR; } conf->jsonbot_password = g_key_file_get_string(conf->keyfile, "jsonbot", "password", &error); if (error) { - fprintf(stderr, "No jsonbot password supplied in the configuration.\n"); + fprintf(stderr, "Error parsing jsonbot password: (%d) %s.\n", error->code, error->message); return ST_CONFIGURATION_ERROR; } conf->jsonbot_privmsg_to = g_key_file_get_string(conf->keyfile, "jsonbot", "privmsg to", &error); if (error) { - fprintf(stderr, "No jsonbot privsmg to supplied in the configuration.\n"); + fprintf(stderr, "Error parsing jsonbot privmsg to: (%d) %s.\n", error->code, error->message); return ST_CONFIGURATION_ERROR; } diff --git a/siahs.c b/siahs.c index e0c6a31..01bab29 100644 --- a/siahs.c +++ b/siahs.c @@ -47,10 +47,6 @@ STATUS parse_siahs_message(TALLOC_CTX *mem_ctx, const char *pkt_prom, const char /* The remaining ptr contains the human readable description string */ - if (strcmp(pkt_prom, prom) != 0) { - return ST_ASSERTION_FAILED; - } - /* Ignore alive! messages */ if (strcmp(code, "alive!") == 0) { DEBUG(2, "Got keepalive packet from prom %s", prom); diff --git a/siahsd-init-script b/siahsd-init-script new file mode 100755 index 0000000..ec07656 --- /dev/null +++ b/siahsd-init-script @@ -0,0 +1,55 @@ +#! /bin/sh +# /etc/init.d/siahsd +# +# Written by Wilco Baan Hofman + +### BEGIN INIT INFO +# Provides: siahsd +# Required-Start: $network +# Required-Stop: $network +# Should-Start: postgresql mysql +# Should-Stop: postgresql mysql +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: SIA-HS Daemon +# Description: SIA-HS Daemon +### END INIT INFO + +DAEMON=/usr/local/src/siahsd/build/siahsd +DAEMON_ARGS= +PIDFILE=/var/run/siahsd.pid + +start() { + echo -n "Starting SIA-HS Daemon: " + if start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS; then + echo "siahsd." + else + echo "FAILED." + return 1 + fi +} + +stop() { + echo -n "Stopping SIA-HS Daemon: " + if start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON; then + echo "siahsd." + else + echo "FAILED." + return 1 + fi +} + + +case $1 in +start) + start + ;; +stop) + stop + ;; +restart) + stop + start + ;; +esac + diff --git a/wscript b/wscript index 6de21a2..f594673 100644 --- a/wscript +++ b/wscript @@ -39,19 +39,20 @@ def configure(conf): # Check for glib conf.check_cfg(package='glib-2.0', uselib_store='glib-2.0', args=['--cflags', '--libs']) - + # Check for talloc conf.check_cfg(package='talloc', uselib_store='talloc', - args=['--cflags', '--libs']) + args=['--cflags', '--libs' ]) - # Check for tevent (Needed for pkg-config of ndr) - conf.check_cfg(package='tevent', uselib_store='tevent', - args=['--cflags', '--libs']) + # Check for samba-4.0 + conf.check_cfg(package='samba-util', uselib_store='samba', + args=['--cflags', '--libs' ]) # Check for ndr - conf.check_cfg(package='ndr', uselib_store='ndr', + conf.check_cfg(package='ndr', uselib_store='samba', args=['--cflags', '--libs']) + # Check for headers conf.check(header_name='stdio.h', features='c cprogram') conf.check(header_name='stdlib.h', features='c cprogram') @@ -69,19 +70,21 @@ def configure(conf): # Used libraries - conf.check(header_name='talloc.h', use='talloc', features='c cprogram') + conf.check(header_name='talloc.h', use='samba', features='c cprogram') conf.check(header_name='glib.h', use='glib-2.0', features='c cprogram') conf.check(header_name='glibconfig.h', use='glib-2.0', features='c cprogram') conf.check(header_name='dbi/dbi.h', features='c cprogram') - + conf.check(header_name='util/data_blob.h', use='samba', features='c cprogram') + conf.check(header_name='core/ntstatus.h', use='samba', features='c cprogram') + conf.check(header_name='charset.h', use='samba', features='c cprogram') conf.check_cc(lib='dbi', uselib_store='dbi') - conf.check_cc(lib='talloc', uselib_store='talloc') + conf.check_cc(lib='talloc', uselib_store='samba') conf.check_cc(lib='ndr', uselib_store='ndr') + conf.check_cc(lib='gmp', uselib_store='nettle') conf.check_cc(lib='hogweed', uselib_store='nettle') conf.check_cc(lib='nettle', uselib_store='nettle') - conf.check_cc(lib='gmp', uselib_store='nettle') # Purposefully at the bottom because waf configuration tests fail with -Wstrict-prototypes and -Werror conf.env.CFLAGS = ['-O0', '-g', '-ggdb', '-std=c99', '-Wall', '-Wshadow', '-Wpointer-arith', '-Wcast-align', '-Wwrite-strings', '-Wdeclaration-after-statement', @@ -98,12 +101,12 @@ def build(bld): bld.program( source = 'siahsd.c', target = 'siahsd', - use = [ 'database', 'config', 'status', 'sia', 'siahs', 'jsonbot', 'dbi', 'talloc','glib-2.0', 'nettle' ]) + use = [ 'database', 'config', 'status', 'sia', 'siahs', 'jsonbot', 'dbi', 'talloc', 'glib-2.0', 'nettle' ]) bld.program( source = 'secip.idl secipd.c crc16.c', target = 'secipd', - use = [ 'database', 'config', 'status', 'sia', 'siahs', 'jsonbot', 'dbi', 'talloc','glib-2.0', 'nettle', 'ndr' ]) + use = [ 'database', 'config', 'status', 'sia', 'siahs', 'jsonbot', 'dbi', 'samba', 'glib-2.0', 'nettle', 'ndr' ]) pass def clean(ctx):