From 7ae9a74c9c3bdab619ac5c0cefe1c8269bb06603 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 24 Sep 2009 00:16:53 +0200 Subject: Rewritten the eurephia_log() to support syslog logging as well Also simplified the initialisation of the logging module. By calling the eurephia_log_init(eurephiaCTX *, char *dest, int loglevel) function, a log context will be setup inside the eurephiaCTX. To close the log file, eurephia_log_close(eurephiaCTX *) must be called. The destination string to eurephia_log_init() can be: - stdout: Log everything to stdout - stderr: Log everything to stderr - none: Do no logging at all - syslog: Log via syslog. can be: user, local[0-7], daemon or authpriv. - Filename All logging goes to the given filename. If the filename string is not recognised by any of the reserved words above, it will be handled as a filename. --- plugin/eurephia-auth.c | 6 +++--- plugin/eurephia.c | 46 +++++++++++--------------------------------- plugin/firewall/eurephiafw.c | 1 - 3 files changed, 14 insertions(+), 39 deletions(-) (limited to 'plugin') diff --git a/plugin/eurephia-auth.c b/plugin/eurephia-auth.c index 3536281..10d9447 100644 --- a/plugin/eurephia-auth.c +++ b/plugin/eurephia-auth.c @@ -189,9 +189,9 @@ OPENVPN_EXPORT int openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, DEBUG(ctx, 10, "openvpn_plugin_func_v1(ctx, %s, ...)", plugin_type_name(type)); #ifdef ENABLE_DEBUG - if( ctx->loglevel >= 30 ) { - dump_env(ctx->log, "ENV: ", envp); - dump_env(ctx->log, "ARG: ", argv); + if( (ctx->log->loglevel >= 30) && (ctx->log->logfile != NULL) ) { + dump_env(ctx->log->logfile, "ENV: ", envp); + dump_env(ctx->log->logfile, "ARG: ", argv); } #endif diff --git a/plugin/eurephia.c b/plugin/eurephia.c index 761ab71..f93ee81 100644 --- a/plugin/eurephia.c +++ b/plugin/eurephia.c @@ -183,26 +183,15 @@ eurephiaCTX *eurephiaInit(const char **argv) ctx->context_type = ECTX_PLUGIN_AUTH; // Open a log file - if( logfile != NULL ) { - if( strcmp(logfile, "openvpn:") == 0 ) { // Let openvpn do the logging - ctx->log = stderr; - } else if( strcmp(logfile, "none:") == 0 ) { // Do not perform any logging - ctx->log = NULL; - } else { // if no hit on these ones,open a file with given name - ctx->log = fopen(logfile, "aw"); - if( ctx->log == NULL ) { - fprintf(stderr, "Could not open eurephia log file: %s\n", argv[1]); - return NULL; - } - } - } else { - // If no logging is given ... log to openvpn: - ctx->log = stderr; + if( (logfile == NULL) || (strcmp(logfile, "openvpn:") == 0) ) { + // If no logfile is given, or openvpn: is given, log to stderr which OpenVPN will + // take care of + eurephia_log_init(ctx, "stderr:", loglvl); + } else { + // If another log file is given, process that + eurephia_log_init(ctx, logfile, loglvl); } - // Set log verbosity - ctx->loglevel = loglvl; - // Load the database driver if( (error == 0) && eDBlink_init(ctx, dbi, 1) ) { // Connect to the database @@ -217,10 +206,8 @@ eurephiaCTX *eurephiaInit(const char **argv) } if( error > 0 ) { - if( ctx->log != NULL ) { - eurephia_log(ctx, LOG_PANIC, 0, "eurephia-auth is not available"); - fclose(ctx->log); - } + eurephia_log(ctx, LOG_PANIC, 0, "eurephia-auth is not available"); + eurephia_log_close(ctx); free_nullsafe(ctx, ctx); return NULL; } @@ -234,7 +221,7 @@ eurephiaCTX *eurephiaInit(const char **argv) free_nullsafe(ctx, ctx->server_salt); eDBdisconnect(ctx); - fclose(ctx->log); + eurephia_log_close(ctx); free_nullsafe(ctx, ctx); return NULL; } @@ -287,18 +274,7 @@ int eurephiaShutdown(eurephiaCTX *ctx) eDBlink_close(ctx); } - if( ctx->log != NULL ) { - fflush(ctx->log); - - // Do not close log file if we're on stdout or stderr - if( (ctx->log != stderr) && (ctx->log != stdout) ) { - eurephia_log(ctx, LOG_INFO, 2, "Closing log file"); - fclose(ctx->log); - } - - ctx->log = NULL; - ctx->loglevel = 0; - } + eurephia_log_close(ctx); memset(ctx->server_salt, 0xff, SIZE_PWDCACHE_SALT+2); free_nullsafe(ctx, ctx->server_salt); diff --git a/plugin/firewall/eurephiafw.c b/plugin/firewall/eurephiafw.c index 0d2cc43..2c6755f 100644 --- a/plugin/firewall/eurephiafw.c +++ b/plugin/firewall/eurephiafw.c @@ -146,7 +146,6 @@ void eFW_StartFirewall(eurephiaCTX *ctx) { shadowctx = (eurephiaCTX *) malloc_nullsafe(ctx, sizeof(eurephiaCTX)+2); assert( shadowctx != NULL ); shadowctx->context_type = ECTX_NO_PRIVILEGES; - shadowctx->loglevel = ctx->loglevel; shadowctx->log = ctx->log; (*ctx->fwcfg).thrdata.ctx = shadowctx; -- cgit From 5aed7f6775777b2a6166d6eddffaa976eb4fac8b Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 24 Sep 2009 17:50:13 +0200 Subject: Added extra parameter to eurephia_log_init() to set log ident for syslog --- plugin/eurephia.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugin') diff --git a/plugin/eurephia.c b/plugin/eurephia.c index f93ee81..db7607f 100644 --- a/plugin/eurephia.c +++ b/plugin/eurephia.c @@ -186,10 +186,10 @@ eurephiaCTX *eurephiaInit(const char **argv) if( (logfile == NULL) || (strcmp(logfile, "openvpn:") == 0) ) { // If no logfile is given, or openvpn: is given, log to stderr which OpenVPN will // take care of - eurephia_log_init(ctx, "stderr:", loglvl); + eurephia_log_init(ctx, "eurephia-auth", "stderr:", loglvl); } else { // If another log file is given, process that - eurephia_log_init(ctx, logfile, loglvl); + eurephia_log_init(ctx, "eurephia-auth", logfile, loglvl); } // Load the database driver -- cgit