diff options
author | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-10-29 15:15:31 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-10-29 15:41:56 +0100 |
commit | a09f0bd8e0c526250aa80895175728fe025c9958 (patch) | |
tree | e324a491bb82642eb82802f2fc098008ee579656 | |
parent | 5fcb1a06cb4b560fee6d1a9c676852bd8f67a9b2 (diff) |
Store log files in /var/log/syslog, also create parent directories
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | syslogd.c | 22 | ||||
-rw-r--r-- | syslogd.h | 2 |
3 files changed, 21 insertions, 14 deletions
@@ -10,7 +10,7 @@ forwards the parsed message to a modular backend interface. Currently, there is only one implementation of the backend interface that dumps the log messages into files in the processes working directory (by default -`/var/log`). +`/var/log/syslog`). A simple log rotation scheme has been implemented. @@ -40,18 +40,11 @@ library and should *in theory* work on any modern GNU/Linux or BSD system. The facility IDs may need to be adjusted (it uses the ones from `usyslogd`). -The file backend of `usyslogd` tries to take over ownership of `/var/log` -and make it inaccessible for all other users. This may be an issue if some -program tries to put its own log files there as non-root user, or programs -that try to read from them as non-root (e.g. `utmp`, `btmp`, `wtmp`, `faillog`, -`lastlog`). - - # The syslog implementation ## Security Considerations -By default, the daemon switches its working directory to `/var/log`. The +By default, the daemon switches its working directory to `/var/log/syslog`. The directory is created if it doesn't exist and the daemon always tries to change its mode to one that doesn't allow other users (except group members) to access the directory. @@ -175,10 +175,24 @@ fail: static int chroot_setup(void) { - if (mkdir(SYSLOG_PATH, 0750)) { - if (errno != EEXIST) { - perror("mkdir " SYSLOG_PATH); - return -1; + size_t i, len = strlen(SYSLOG_PATH); + char *buffer = alloca(len + 1); + + memcpy(buffer, SYSLOG_PATH, len + 1); + + for (i = 0; i < len; ++i) { + if (buffer[i] == '\0' || buffer[i] == '/') { + buffer[i] = '\0'; + + if (mkdir(buffer, 0755)) { + if (errno != EEXIST) { + perror(buffer); + return -1; + } + } + + if (i < (len - 1)) + buffer[i] = '/'; } } @@ -11,7 +11,7 @@ #define SYSLOG_SOCKET "/dev/log" -#define SYSLOG_PATH "/var/log" +#define SYSLOG_PATH "/var/log/syslog" #define DEFAULT_USER "syslogd" #define DEFAULT_GROUP "syslogd" |