From 02d56db68da9365e256f00cfd51227b485f96841 Mon Sep 17 00:00:00 2001 From: venaas Date: Mon, 7 May 2007 09:24:46 +0000 Subject: Can now specifiy syslog facility git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@73 e88ac4ed-0b26-0410-9574-a7f39faa03bf --- debug.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'debug.c') diff --git a/debug.c b/debug.c index e5908e2..d7d333b 100644 --- a/debug.c +++ b/debug.c @@ -38,7 +38,14 @@ uint8_t debug_get_level() { } int debug_set_destination(char *dest) { + static const char *facstrings[] = { "LOG_DAEMON", "LOG_MAIL", "LOG_USER", "LOG_LOCAL0", + "LOG_LOCAL1", "LOG_LOCAL2", "LOG_LOCAL3", "LOG_LOCAL4", + "LOG_LOCAL5", "LOG_LOCAL6", "LOG_LOCAL7", NULL }; + static const int facvals[] = { LOG_DAEMON, LOG_MAIL, LOG_USER, LOG_LOCAL0, + LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, + LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7 }; extern int errno; + int i; if (!strncasecmp(dest, "file:///", 8)) { debug_file = fopen(dest + 7, "a"); @@ -48,12 +55,22 @@ int debug_set_destination(char *dest) { setvbuf(debug_file, NULL, _IONBF, 0); return 1; } - if (!strcasecmp(dest, "x-syslog://")) { - debug_syslogfacility = LOG_DAEMON; + if (!strncasecmp(dest, "x-syslog://", 11)) { + dest += 11; + if (*dest) { + for (i = 0; facstrings[i]; i++) + if (!strcasecmp(dest, facstrings[i])) + break; + if (!facstrings[i]) + debugx(1, DBG_ERR, "Unknown syslog facility %s", dest); + debug_syslogfacility = facvals[i]; + } else + debug_syslogfacility = LOG_DAEMON; openlog(debug_ident, LOG_PID, debug_syslogfacility); return 1; } - return 0; + debug(DBG_ERR, "Unknown log destination, exiting %s", dest); + exit(1); } void debug_logit(uint8_t level, const char *format, va_list ap) { -- cgit v1.2.3