Harden the build system. Fix configuration error processing.
This commit is contained in:
parent
51fbbfb078
commit
214d2f2f31
5 changed files with 121 additions and 45 deletions
65
config.c
65
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)) {
|
if (!g_key_file_load_from_file (conf->keyfile, CONFIGFILE, 0, &error)) {
|
||||||
g_error (error->message);
|
g_error (error->message);
|
||||||
|
g_error_free(error);
|
||||||
return ST_CONFIGURATION_ERROR;
|
return ST_CONFIGURATION_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = g_key_file_get_string(conf->keyfile, "siahsd", "event handlers", &error);
|
buf = g_key_file_get_string(conf->keyfile, "siahsd", "event handlers", &error);
|
||||||
if (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;
|
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 */
|
/* Initialize the required event handler backends */
|
||||||
ptr = strtok(buf, " ");
|
ptr = strtok(buf, " ");
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
do {
|
do {
|
||||||
DEBUG(0, "%s\n", ptr);
|
|
||||||
if (strcmp(ptr, "database") == 0) {
|
if (strcmp(ptr, "database") == 0) {
|
||||||
database_init();
|
database_init();
|
||||||
} else if (strcmp(ptr, "jsonbot") == 0) {
|
} else if (strcmp(ptr, "jsonbot") == 0) {
|
||||||
|
@ -138,32 +164,23 @@ STATUS read_configuration_file(TALLOC_CTX *mem_ctx)
|
||||||
} while((ptr = strtok(NULL, " ")) != NULL);
|
} 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 */
|
/* Optional parameters are protocol-specific */
|
||||||
/* FIXME Warn the user when these aren't configured */
|
/* FIXME Warn the user when these aren't configured */
|
||||||
conf->siahs_port = g_key_file_get_integer(conf->keyfile, "siahs", "port", &error);
|
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);
|
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);
|
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;
|
return ST_OK;
|
||||||
}
|
}
|
||||||
|
|
15
jsonbot.c
15
jsonbot.c
|
@ -33,6 +33,11 @@ STATUS jsonbot_notify(TALLOC_CTX *mem_ctx, const char *prom, const char *code, c
|
||||||
|
|
||||||
conf = get_conf();
|
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);
|
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);
|
conf->jsonbot_address = g_key_file_get_string(conf->keyfile, "jsonbot", "address", &error);
|
||||||
if (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;
|
return ST_CONFIGURATION_ERROR;
|
||||||
}
|
}
|
||||||
conf->jsonbot_port = g_key_file_get_integer(conf->keyfile, "jsonbot", "port", &error);
|
conf->jsonbot_port = g_key_file_get_integer(conf->keyfile, "jsonbot", "port", &error);
|
||||||
if (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;
|
return ST_CONFIGURATION_ERROR;
|
||||||
}
|
}
|
||||||
conf->jsonbot_aeskey = g_key_file_get_string(conf->keyfile, "jsonbot", "aes key", &error);
|
conf->jsonbot_aeskey = g_key_file_get_string(conf->keyfile, "jsonbot", "aes key", &error);
|
||||||
if (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;
|
return ST_CONFIGURATION_ERROR;
|
||||||
}
|
}
|
||||||
conf->jsonbot_password = g_key_file_get_string(conf->keyfile, "jsonbot", "password", &error);
|
conf->jsonbot_password = g_key_file_get_string(conf->keyfile, "jsonbot", "password", &error);
|
||||||
if (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;
|
return ST_CONFIGURATION_ERROR;
|
||||||
}
|
}
|
||||||
conf->jsonbot_privmsg_to = g_key_file_get_string(conf->keyfile, "jsonbot", "privmsg to", &error);
|
conf->jsonbot_privmsg_to = g_key_file_get_string(conf->keyfile, "jsonbot", "privmsg to", &error);
|
||||||
if (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;
|
return ST_CONFIGURATION_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
siahs.c
4
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 */
|
/* The remaining ptr contains the human readable description string */
|
||||||
|
|
||||||
if (strcmp(pkt_prom, prom) != 0) {
|
|
||||||
return ST_ASSERTION_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ignore alive! messages */
|
/* Ignore alive! messages */
|
||||||
if (strcmp(code, "alive!") == 0) {
|
if (strcmp(code, "alive!") == 0) {
|
||||||
DEBUG(2, "Got keepalive packet from prom %s", prom);
|
DEBUG(2, "Got keepalive packet from prom %s", prom);
|
||||||
|
|
55
siahsd-init-script
Executable file
55
siahsd-init-script
Executable file
|
@ -0,0 +1,55 @@
|
||||||
|
#! /bin/sh
|
||||||
|
# /etc/init.d/siahsd
|
||||||
|
#
|
||||||
|
# Written by Wilco Baan Hofman <wilco@baanhofman.nl>
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
25
wscript
25
wscript
|
@ -42,16 +42,17 @@ def configure(conf):
|
||||||
|
|
||||||
# Check for talloc
|
# Check for talloc
|
||||||
conf.check_cfg(package='talloc', uselib_store='talloc',
|
conf.check_cfg(package='talloc', uselib_store='talloc',
|
||||||
args=['--cflags', '--libs'])
|
args=['--cflags', '--libs' ])
|
||||||
|
|
||||||
# Check for tevent (Needed for pkg-config of ndr)
|
# Check for samba-4.0
|
||||||
conf.check_cfg(package='tevent', uselib_store='tevent',
|
conf.check_cfg(package='samba-util', uselib_store='samba',
|
||||||
args=['--cflags', '--libs'])
|
args=['--cflags', '--libs' ])
|
||||||
|
|
||||||
# Check for ndr
|
# Check for ndr
|
||||||
conf.check_cfg(package='ndr', uselib_store='ndr',
|
conf.check_cfg(package='ndr', uselib_store='samba',
|
||||||
args=['--cflags', '--libs'])
|
args=['--cflags', '--libs'])
|
||||||
|
|
||||||
|
|
||||||
# Check for headers
|
# Check for headers
|
||||||
conf.check(header_name='stdio.h', features='c cprogram')
|
conf.check(header_name='stdio.h', features='c cprogram')
|
||||||
conf.check(header_name='stdlib.h', features='c cprogram')
|
conf.check(header_name='stdlib.h', features='c cprogram')
|
||||||
|
@ -69,19 +70,21 @@ def configure(conf):
|
||||||
|
|
||||||
|
|
||||||
# Used libraries
|
# 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='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='glibconfig.h', use='glib-2.0', features='c cprogram')
|
||||||
|
|
||||||
conf.check(header_name='dbi/dbi.h', 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='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='ndr', uselib_store='ndr')
|
||||||
|
conf.check_cc(lib='gmp', uselib_store='nettle')
|
||||||
conf.check_cc(lib='hogweed', uselib_store='nettle')
|
conf.check_cc(lib='hogweed', uselib_store='nettle')
|
||||||
conf.check_cc(lib='nettle', 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
|
# 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',
|
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(
|
bld.program(
|
||||||
source = 'siahsd.c',
|
source = 'siahsd.c',
|
||||||
target = 'siahsd',
|
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(
|
bld.program(
|
||||||
source = 'secip.idl secipd.c crc16.c',
|
source = 'secip.idl secipd.c crc16.c',
|
||||||
target = 'secipd',
|
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
|
pass
|
||||||
|
|
||||||
def clean(ctx):
|
def clean(ctx):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue