Commit Graph

110 Commits

Author SHA1 Message Date
Joachim Nilsson
ec06b220e4 If available, use O_TMPFILE, fix insecure tempfile found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 07:04:06 +01:00
Joachim Nilsson
3cff584621 Refactor wallmsg() slightly, fixes "unused value" found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 07:03:57 +01:00
Joachim Nilsson
e8674a8fd7 Check return value from setsockopt(), found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 15:56:47 +01:00
Joachim Nilsson
3c2c353c37 Handle open() errors during log rotation, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 11:04:44 +01:00
Joachim Nilsson
0bf36c59a6 Refactor, close() may try to close -1, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 10:28:26 +01:00
Joachim Nilsson
2e8dffe893 If fstat() failes logrotate() cannot run, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 10:23:17 +01:00
Joachim Nilsson
1fe3c311ca Ignore return value from rename() to silence Coverity Scan
If we cannot rename our own files we're in a bit of a pickle.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 10:21:58 +01:00
Joachim Nilsson
58b243ea55 Replace unsafe strncpy() and strcpy() with safe strlcpy(),
C.f. Coverity CID 1076404

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 10:10:06 +01:00
Joachim Nilsson
f6ecb8b47b Fix Coverity CID 1406626, avoid strncat() in favor of snprintf()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 09:37:07 +01:00
Joachim Nilsson
a4b09cc15b Clarify comment, _PATH_LOG applies to *sysklogd project*
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 08:57:15 +01:00
Joachim Nilsson
2fcfc0ad81 Drop #include "config.h" from syslog.h
Should not be in an exported header, obviously.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 08:42:29 +01:00
Joachim Nilsson
e202196152 Add missing files to distribution, found by make distcheck
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 20:09:15 +01:00
Joachim Nilsson
58da3b6bd2 Mark strlcat() and strlcpy() as weak functions, for libsyslog
The strlcat() and strlcpy() functions are only intended to be used
by syslog.c internally (and syslogd), when building libsyslog.

A user linking with libsyslog may have another library that provides
strlcat() or strlcpy() replacements.  We must therefore mark ours as
weak functions so they can be overridden.

This patch also add a convenience library for libsyslog, to control
the build deps. for libsyslog.  This is where external dependencies
should be addded (explicitly) when syslog.c is updated from NetBSD.
If you add new deps you likely want to mark them too as weak refs.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 11:04:13 +01:00
Joachim Nilsson
8f66822b2a Check for getprogname() et al, and use config.h for #ifndefs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 10:55:52 +01:00
Joachim Nilsson
ad70b49790 Minor, whitspace alignment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 06:21:50 +01:00
Joachim Nilsson
024dde00c2 Remove unused files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 21:14:45 +01:00
Joachim Nilsson
11a16e16b8 syslogd: Strip whitespace in rule between action and option
Terminate action filename/pipe/host so we don't get any trailing tab or
space character in file or host names.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 19:48:22 +01:00
Joachim Nilsson
ff27d39cca syslogd: Fix double free() warning after SIGHUP
This cleanup section has moved to *after* cfparse()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 19:47:54 +01:00
Joachim Nilsson
b2940cade1 Remove old Makefile, not needed anymore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 17:30:12 +01:00
Joachim Nilsson
ea565153bc Remove last remnants of TESTING define
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 17:29:52 +01:00
Joachim Nilsson
3a825cf0da Update GPL license headers, wrong address for FSF
- Update last paragraph, with FSF address
- Drop gratuitous "this file is part of the sysklogd package"
- Fix indentation
- Update copyright years for my own contributions

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 17:21:06 +01:00
Joachim Nilsson
c05956010c Make sure libsyslog.la, incl. strlcpy.o, is built with -fPIC
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 15:55:25 +01:00
Joachim Nilsson
fe3066f4c2 Connect to syslogd using SYSLOG_UNIX_PATH variable, if set
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 15:52:13 +01:00
Joachim Nilsson
84aa897628 Consolidate option parsing for syslog.conf rules
This patch changes the syntax for per-rule log rotation and makes it
possible to have enable log rotation and RFC5424 output formatting.

The new syntax looks like this:

    	EXPR		ACTION			;OPT,OPT,...

Example:

	*.notice	-/var/log/messages	;rotate=1M:5,RFC5424

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 12:15:05 +01:00
Joachim Nilsson
4066a1e9bf Add FreeBSD facilities: LOG_NTP, LOG_SECURITY, LOG_CONSOLE, ...
This patch is a major refactor of the priority and facility parsing in
syslogd.  The "new" facilities are taken from FreeBSD and are de facto
interpretations of facilities otherwise "reserved for system use", as
GLIBC syslog.h puts it.

___
... and LOG_CRON_SOL, but only for completness.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 08:21:44 +01:00
Joachim Nilsson
ff4f2cdb31 Replace homegrown PID file functions with std BSD pidfile()
- Import pidfile() v1.11 from OpenBSD and libite (-lite) project
- Import utimensat() replacement, for systems that don't have it
- Simplify syslogd and klogd program start and PID file creation
- Rip out -i and -I from klogd, uses old PID file functions, and
  they're only kill(1) wrappers anyway

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-02 21:03:28 +01:00
Joachim Nilsson
1236334c39 Fix some memory leaks, found by Valgrind
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-02 21:03:28 +01:00
Joachim Nilsson
917ef4ed1d Add support for include /etc/syslog.d/*.conf in /etc/syslog.conf
- Massive refactor of the .conf file parsing
- Add queue.h v1.43 from OpenBSD, has _SAFE versions unlike GLIBC queue.h
- Use queue.h list macros instead of homegrown linked list
- Adopt NetBSD reconf style; on failure to reload keep old config

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-02 11:46:29 +01:00
Joachim Nilsson
ddaa0a1a82 Factor out ConfFile parsing to separate function
Also, fix segfault when syslogd is started without a .conf file.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-31 19:37:37 +01:00
Joachim Nilsson
aad95082fb Drop -fno-strength-reduce from default CFLAGS not supported by Clang
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-31 10:13:36 +01:00
Joachim Nilsson
af97a5bb0a Build libsyslog.la and install it with syslog.h and libsyslog.pc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-31 08:39:09 +01:00
Joachim Nilsson
72bbee7812 syslogd: Add support for '-b :service' to bind to another port
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-30 17:08:26 +01:00
Joachim Nilsson
a1e5680aee Disable logger default file rotation, must now be enabled with -r
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-30 09:30:42 +01:00
Joachim Nilsson
eb10b94f55 Update usage text; -b/-c removed in favor of -R
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-30 09:19:54 +01:00
Joachim Nilsson
fc4840a698 Add support for -P pid_file, like FreeBSD syslogd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 13:58:56 +01:00
Joachim Nilsson
b67d57cf59 Initial test framework: make check
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 13:58:56 +01:00
Joachim Nilsson
ec9c92987f Add support for logger -u /tmp/foo to log to alternate socket
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 10:43:14 +01:00
Joachim Nilsson
08aa942ffb Minor, staticify global variables and fix indentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 10:42:45 +01:00
Joachim Nilsson
48a9f1fdd7 Remove old TESTING mode, incl. tsyslogd and syslog-tst
This special build option enabled reading syslog messages from stdin on
syslogd.  It also disabled all other standard features of syslogd, which
made it a bit too far from the real thing.

A better approac is to start syslogd with -p /tmp/foo and let a test
application, e.g. logger -u /tmp/foo, connect using the standard UNIX
domain socket API.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 10:39:56 +01:00
Joachim Nilsson
b6dcef71dd Enable remote syslog messages for testing
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 09:09:05 +01:00
Joachim Nilsson
176ba2d095 Support for logging to a file/stdout using syslog API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 09:08:37 +01:00
Joachim Nilsson
ee2d0ce106 Sync with FreeBSD syslogd to get full RFC5424 support
This massive patch brings support for parsing incoming syslog messages,
remote or local, to determine if format is RFC5424 or the older RFC3164.
For logging syslogd currently defaults to RFC3164 for local files and
supports RFC5424 for sending to remote servers.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 09:01:01 +01:00
Joachim Nilsson
4f45f3c22f Minor, misc cleanup and simplification
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 08:59:54 +01:00
Joachim Nilsson
e9a546c683 Only chdir("/") when detaching from TTY and backgrounding process
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 08:54:30 +01:00
Joachim Nilsson
4f5124cb79 Change command line option for log rotation, from -b/-c --> -R b:c
We want to use -b for binding to an address:port, like FreeBSD/NetBSD
supports using this option.  Unfortunately breaks existing setups in
the wild already.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-29 06:37:55 +01:00
Joachim Nilsson
b66090ce4f Minor, sync variable name with FreeBSD
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-28 20:42:40 +01:00
Joachim Nilsson
4c6aa23dba Add missing include guards
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-27 21:32:37 +01:00
Joachim Nilsson
bf448fc6a1 Remove historical changelogs from files
We don't need to carry it any longer.  Anyone who wants to read them can
access an older GIT version, or released tarball.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-27 21:30:41 +01:00
Joachim Nilsson
0603849891 syslogd need _XOPEN_SOURCE for strptime()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-27 21:27:30 +01:00
Joachim Nilsson
19f09ebb9d Change to use local version of syslog.h in syslogd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-10-26 19:10:19 +02:00