diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-12-16 16:48:58 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-12-16 16:48:58 +0100 |
commit | 7f7041b1ff851bed8932fecb8d2a4a991d177721 (patch) | |
tree | 1de2227f8502436aaa2de0217e91155f7d66e30f /src | |
parent | 8e9c9bc6ec2877f73e0ecdfd25fbf96464f08885 (diff) | |
download | fastd-7f7041b1ff851bed8932fecb8d2a4a991d177721.tar fastd-7f7041b1ff851bed8932fecb8d2a4a991d177721.zip |
Never write to syslog/log files during key generation
Diffstat (limited to 'src')
-rw-r--r-- | src/fastd.c | 9 | ||||
-rw-r--r-- | src/fastd.h | 1 | ||||
-rw-r--r-- | src/log.c | 18 |
3 files changed, 16 insertions, 12 deletions
diff --git a/src/fastd.c b/src/fastd.c index c75fa9b..3cc7d37 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -133,6 +133,8 @@ static void init_log(fastd_context_t *ctx) { ctx->log_files = file; } + ctx->log_initialized = true; + if (seteuid(uid) < 0) pr_debug_errno(ctx, "seteuid"); if (setegid(gid) < 0) @@ -757,15 +759,11 @@ int main(int argc, char *argv[]) { fastd_config_t conf; fastd_configure(&ctx, &conf, argc, argv); - init_log(&ctx); - if (conf.generate_key) { conf.protocol->generate_key(&ctx); exit(0); } - init_signals(&ctx); - conf.protocol_config = conf.protocol->init(&ctx); if (conf.show_key) { @@ -773,6 +771,9 @@ int main(int argc, char *argv[]) { exit(0); } + init_log(&ctx); + init_signals(&ctx); + update_time(&ctx); conf.long_ago = ctx.now; diff --git a/src/fastd.h b/src/fastd.h index 76a71da..b170bb5 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -242,6 +242,7 @@ struct fastd_config { struct fastd_context { const fastd_config_t *conf; + bool log_initialized; fastd_log_fd_t *log_files; char *ifname; @@ -234,7 +234,7 @@ void fastd_logf(const fastd_context_t *ctx, fastd_loglevel_t level, const char * buffer[sizeof(buffer)-1] = 0; - if (ctx->conf == NULL || level <= ctx->conf->log_stderr_level || ctx->conf->log_files) { + if (!ctx->log_initialized || level <= ctx->conf->log_stderr_level || ctx->conf->log_files) { time_t t; struct tm tm; @@ -245,15 +245,17 @@ void fastd_logf(const fastd_context_t *ctx, fastd_loglevel_t level, const char * } } - if (ctx->conf == NULL || level <= ctx->conf->log_stderr_level) + if (!ctx->log_initialized || level <= ctx->conf->log_stderr_level) fprintf(stderr, "%s%s%s\n", timestr, get_log_prefix(level), buffer); - if (ctx->conf != NULL && level <= ctx->conf->log_syslog_level) - syslog(get_syslog_level(level), "%s", buffer); + if (ctx->log_initialized) { + if (level <= ctx->conf->log_syslog_level) + syslog(get_syslog_level(level), "%s", buffer); - fastd_log_fd_t *file; - for (file = ctx->log_files; file; file = file->next) { - if (level <= file->config->level) - dprintf(file->fd, "%s%s%s\n", timestr, get_log_prefix(level), buffer); + fastd_log_fd_t *file; + for (file = ctx->log_files; file; file = file->next) { + if (level <= file->config->level) + dprintf(file->fd, "%s%s%s\n", timestr, get_log_prefix(level), buffer); + } } } |