diff options
author | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-01-05 17:21:28 +0000 |
---|---|---|
committer | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-01-05 17:21:28 +0000 |
commit | 974d151ef8587d5ba3b6442eec500fefb18b4a9c (patch) | |
tree | 233326ecdc75955f0048c64e999018260c15293a | |
parent | 1102a95296e39f671efe51bb6bd9b30e5c14c91e (diff) | |
download | conntrack-tools-974d151ef8587d5ba3b6442eec500fefb18b4a9c.tar.gz conntrack-tools-974d151ef8587d5ba3b6442eec500fefb18b4a9c.zip |
fix logfiles permissions, do not default to umask
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/log.c | 38 | ||||
-rw-r--r-- | src/main.c | 4 |
3 files changed, 34 insertions, 9 deletions
@@ -32,6 +32,7 @@ o detach daemon from its terminal (Ben Lenitz <BLentz@channing-bete.com>) o obsolete `-S' option: Use information provided by the config file o daemonize conntrackd after initialization o rename class `buffer' to `queue' which is what it really implements +o fix logfiles permissions, do not default to umask version 0.9.5 (2007/07/29) ------------------------------ @@ -19,28 +19,54 @@ */ #include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include <time.h> #include <stdarg.h> #include <string.h> +#include <errno.h> #include "buffer.h" #include "conntrackd.h" int init_log(void) { if (CONFIG(logfile)[0]) { - STATE(log) = fopen(CONFIG(logfile), "a+"); + int fd; + + fd = open(CONFIG(logfile), O_CREAT | O_RDWR, 0600); + if (fd == -1) { + fprintf(stderr, "ERROR: can't open logfile `%s'." + "Reason: %s\n", CONFIG(logfile), + strerror(errno)); + return -1; + } + + STATE(log) = fdopen(fd, "a+"); if (STATE(log) == NULL) { - fprintf(stderr, "can't open log file `%s'\n", - CONFIG(logfile)); + fprintf(stderr, "ERROR: can't open logfile `%s'." + "Reason: %s\n", CONFIG(logfile), + strerror(errno)); return -1; } } if (CONFIG(stats).logfile[0]) { - STATE(stats_log) = fopen(CONFIG(stats).logfile, "a+"); + int fd; + + fd = open(CONFIG(stats).logfile, O_CREAT | O_RDWR, 0600); + if (fd == -1) { + fprintf(stderr, "ERROR: can't open logfile `%s'." + "Reason: %s\n", CONFIG(stats).logfile, + strerror(errno)); + return -1; + } + + STATE(stats_log) = fdopen(fd, "a+"); if (STATE(stats_log) == NULL) { - fprintf(stderr, "can't open log file `%s'\n", - CONFIG(stats).logfile); + fprintf(stderr, "ERROR: can't open logfile `%s'." + "Reason: %s\n", CONFIG(stats).logfile, + strerror(errno)); return -1; } } @@ -246,10 +246,8 @@ int main(int argc, char *argv[]) /* * Setting up logging */ - if (config_set && init_log() == -1) { - fprintf(stderr, "can't open logfile `%s\n'", CONFIG(logfile)); + if (config_set && init_log() == -1) exit(EXIT_FAILURE); - } if (type == REQUEST) { if (do_local_request(action, &conf.local, local_step) == -1) { |