Commit graph

400 commits

Author SHA1 Message Date
Lexi Winter dbd0366f34 package: move lpr into its own package
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1171
2024-04-19 16:54:31 -06:00
Warner Losh 0b8224d1cc Remove copyright strings ifdef'd out
We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by:		Netflix
2023-11-26 22:23:58 -07:00
Warner Losh 8a7b612037 usr.sbin: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:56 -07:00
Jake Freeland d556719e15 syslogd: Keep console and tty descriptors open
Console and tty descriptors are initially opened in parse_action() to
determine whether they are valid using isatty(). That descriptor is then
closed because it is never accessed by syslogd again; ttymsg() will reopen
the tty/console under a new descriptor when needed.

If the user attempts to log to a tty that is inactive outside of
syslogd, then syslogd must keep that descriptor open so the tty remains
accessible. For example, logging to `/dev/ttyvb` requires the initial
`/dev/ttyvb` descriptor to stay open so the user can view its buffer at
any time via CTRL+ALT+F12.

As a result, console and tty descriptors must remain open until a
potential configuration reload or a system shutdown. The given
descriptor will be closed in close_filed() in such circumstances.

PR:		274454
Fixes:		c3175a6e1c ("syslogd: Do not open console descriptor")
Reported by:	Trond Endrestøl <Trond.Endrestol@ximalas.info>
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D42215
2023-10-16 09:11:58 -04:00
Olivier Cochard 75ae7e436e syslogd: Prevent running tests in parallel
They all use the same listening port.

Approved by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D41989
2023-10-11 12:24:42 +02:00
Jake Freeland 94cae4cb33 syslogd: Do not add shutdown sockets to the kqueue
If syslogd is in secure mode, all INET sockets are shutdown. Do not
add these to the kqueue because we can't read from them.

Also, remove the listen() call when setting up sockets. Syslogd
exclusively uses SOCK_DGRAM sockets, so calling listen() is useless.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41526
2023-09-28 11:51:54 -04:00
Jake Freeland 8536447a07 syslogd: Use pipe to communicate with daemon
Previously, syslogd's daemon process would signal that it had finished
initialization using SIGALRM. In capability mode, signal delivery is not
allowed, so use a pipe to indicate that it is ready to accept messages.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41459
2023-09-28 11:51:54 -04:00
Jake Freeland 4ac6582472 syslogd: Ignore signals in sigcatch[]
Instead of blocking signals in sigcatch[], just ignore them. This frees
up some space on the proc's sigqueue.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41433
2023-09-28 11:51:54 -04:00
Jake Freeland 7428ebfe7e syslogd: Pre-open null file descriptor
Open _PATH_DEVNULL before entering capability mode. Access to /dev/null
is needed for dup2() when piping commands.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41381
2023-09-28 11:51:54 -04:00
Jake Freeland c3175a6e1c syslogd: Do not open console descriptor
Setup consfile filed for logging while Initialized is false, but do not
bother opening the console. Close console/tty descriptors after parsing,
as well. The ttymsg() function will re-open these descriptors for us.

Also, remove references to the ctty global variable since it will always
be _PATH_CONSOLE.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41380
2023-09-28 11:51:54 -04:00
Jake Freeland 5b44c24f85 syslogd: unlink() -> unlinkat()
Save basename and dirname for use in unlinkat() when removing UNIX
sockets from fs.

Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41379
2023-09-28 11:51:53 -04:00
Jake Freeland 3854dd52a3 syslogd: Add closelogfiles() function
The closelogfiles() function completely disassembles the global filed
list by freeing all filed components and removing them from the list.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41388
2023-09-28 11:51:53 -04:00
Jake Freeland 09080d8ec5 syslogd: Fix sizeof() styling
Use parentheses when applying sizeof() per style(9).

Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41376
2023-09-28 11:51:53 -04:00
Jake Freeland 8f49f83ef5 syslogd: Move action parsing into its own function
Clean up the cfline() function by moving action parsing into its own
function.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41375
2023-09-28 11:51:53 -04:00
Jake Freeland f4b4a10abb syslogd: Move selector parsing into its own function
Clean up the cfline() function by moving selector parsing into its
own function.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41374
2023-09-28 11:51:53 -04:00
Jake Freeland 688ecad8e1 syslogd: Move prop_filter allocation into function
Clean up the cfline() function by moving the prop_filter memory
allocation into the prop_filter_compile() function.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41373
2023-09-28 11:51:53 -04:00
Jake Freeland cd90f3afb7 syslogd: Do not print bad data
If errno is zero, then buf is never filled and we're printing
uninitialized data. Print the msg buffer instead to mitigate this.

Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41371
2023-09-28 11:51:53 -04:00
Jake Freeland bbde787c66 syslogd: Merge loops
Merge the two loops that traverse the global filed queue. Both loops'
actions are not dependent on the other, so combining them is safe.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41370
2023-09-28 11:51:53 -04:00
Jake Freeland fe233250d6 syslogd: Do not reap child processes
Use the SA_NOCLDWAIT sigaction() flag to disable the creation of
zombie processes. This leaves no reason to wait() on children, so
remove the reaping routine.

Previously, deadq entries were removed in reapchild(). Move deadq
removal into markit() after SIGKILL is sent.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41415
2023-09-28 11:51:53 -04:00
Jake Freeland 95381c0139 syslogd: Use process descriptors
Prepare for program Capsicumization by storing process descriptors
instead of pids. Signal delivery is not permitted in capability mode,
so we can use pdkill(2) to terminate child processes.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41369
2023-09-28 11:51:53 -04:00
Jake Freeland 599db1e026 syslogd: Simplify filed structure
Rearrange fields and add some comments.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41368
2023-09-28 11:51:53 -04:00
Jake Freeland 929568b9d5 syslogd: Style fixes
Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41367
2023-09-28 11:51:53 -04:00
Jake Freeland fcc1e1777d syslogd: Simplify property filters
* Use enums for property filter properties and comparisons.
* Rename property and comparison values.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41366
2023-09-28 11:51:53 -04:00
Jake Freeland b772f1ce14 syslogd: Clean up allowedpeer structure
* Use boolean values in validate() and struct allowedpeer.
* Remove useless peer count loop.

Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41365
2023-09-28 11:51:53 -04:00
Jake Freeland f30b063ee6 syslogd: Only use peerlist during flag parsing
Add logging sockets directly to the socklist, unless parsing flags. The
peerlist is still needed to temporarily hold socket information until
the configuration flags have been parsed.

It is tempting to remove the entire peerlist, but addsock() can not
determine if syslogd is in secure mode unless the flags have been
parsed.

Also, call pidfile_open() right after flag parsing so we can terminate
if another syslogd instance is already running.

Reviewed by:	markj
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41364
2023-09-28 11:51:52 -04:00
Jake Freeland 1bb61348e6 syslogd: Use boolean reload parameter for init()
Replace init()'s integer "signo" parameter with boolean "reload"
for clarity.

Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41416
2023-09-28 11:51:52 -04:00
Jake Freeland f804f23650 syslogd: Centralize operations into a kevent loop
Use kqueue(2) for socket I/O and signal notification. Previously,
select(2) and traditional signal handlers were being used.

This change centralizes all of the async notification delivery into a
single loop so future Capsicum sandboxing will be easier. It also
simplifies the code by removing boiler-plate cruft that comes with the
older interfaces.

Reviewed by:	Slawa Olhovchenkov, markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41363
2023-09-28 11:51:52 -04:00
Jake Freeland 3f8b49dd1a syslogd: Replace int with bool, where applicable
Many of syslogd's global configuration options are declared as integers
but are treated as booleans. Declare those options as booleans instead.

Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41362
2023-09-28 11:51:52 -04:00
Jake Freeland 8113e030f9 syslogd: Move fhead under filed struct declaration
Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41360
2023-09-28 11:51:52 -04:00
Jake Freeland 2d69e4c373 syslogd: Remove addfile() and free up some memory
cfline() already allocates a filed structure on the heap, so we can
avoid redundant memory allocations by skipping a second calloc() inside
addfile().

addfile() can be removed altogether since a simple STAILQ_INSERT_TAIL()
will add the filed to the global filed list.

Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41359
2023-09-28 11:51:52 -04:00
Jake Freeland 931d05fc08 syslogd: Read configuration outside of init loop
Move all configuration-file code outside of the initialization loop and
into its own set of functions. Create a readconfigfile() to open the
config and call parseconfigfile() to parse it.

The init() function no longer returns if there was a failure to open the
configuration file. Initialization will be finished, using the backup
logging rules: *.ERR to /dev/console and *.PANIC to all logged in users.

Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41358
2023-09-28 11:51:52 -04:00
Mark Johnston 518bd54167 syslogd: Fix fd type, add enum for filed types
Reviewed by:	markj, emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41357
2023-09-28 11:51:52 -04:00
Jake Freeland fcace2906d syslogd: Add some basic regression tests
Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41403
2023-08-23 12:17:40 -04:00
Warner Losh b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh 42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Vadim Goncharov a81b559dad Fix saving STRUCTURED-DATA in RFC 5424 log format
When saving log files in RFC 5424 format presence of STRUCTURED-DATA
in message caused line to not appear in log file at all, because
a variable forgotten to initialize. This could be tested by (slightly
modified) example from RFC:

    echo '<165>1 2003-10-11T22:14:15.003Z mymachine.example.com su 12345 ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"][id@2 test="tast"] BOM"su root" failed for lonvick on /dev/pts/8" ' | nc -w1 -Uu /var/run/log

While here, update stale information in comment to logmsg() that RFC 5424
log format was not supported.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/717
2023-07-06 23:15:10 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Simon J. Gerraty d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Emmanuel Vadot 25367c806b pkgbase: Create a FreeBSD-syslogd package
This allow one to not install syslogd and use syslog-ng or any other
syslog daemon.
While here put some syslog.d file in their own package.

MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33455
2021-12-21 10:17:40 +01:00
jfranklin13 9589362bc9 syslogd: Fix bug that caused -N to drop SecureMode if specified after -s
MFC after:	2 weeks
Pull Request:	https://github.com/freebsd/freebsd-src/pull/541
2021-09-29 09:44:11 -04:00
Eugene Grosbein 3b4cc56e52 syslogd: undo regression after r326573
Restore ability for our syslogd to collect pre-RFC3164 formatted
messages from remote hosts that was broken with r326573.

For example, the line from Cisco SCE8000 splitted for readability:

1130: 03:37:57: %USER-6-PORT_OPERSTATUS_CHANGE_TRAP: CPU#000 trap:link
down EntityAdminState: 4  EntityAlarmStatus: 32

Such line was collected and stored before mentioned change
but silently dropped after that. Now syslogd saves it again.

Note that parsing of RFC5424 format not changed.

MFC after:	1 month
2021-09-27 14:25:21 +07:00
Felix Guest 8678140127 syslog.conf.5: Fix the message priority order
PR:		219942
MFC after:	1 week
2021-09-21 12:07:39 -04:00
Artem Khramov f06fa6f887 syslogd: fix WITHOUT_INET builds
Since 2d82b47 syslogd can't be built with `WITHOUT_INET` or
`WITHOUT_INET6` build variables set, because `iovlist_truncate` is not
defined but used.

This change wraps the problematic `iovlist_truncate` call within ifdef
directive.  It's compiled out in this situation...

Pull Request:	https://github.com/freebsd/freebsd-src/pull/475
Reviewed by:	imp@ (commit message slightly tweaked)
2021-06-12 22:25:35 -06:00
Dmitry Wagin 2d82b47a5b syslogd: Increase message size limits
Add a -M option to control the maximum length of forwarded messages.
syslogd(8) used to truncate forwarded messages to 1024 bytes, but after
commit 1a874a126a ("Add RFC 5424 syslog message output to syslogd.")
applies a more conservative limit of 480 bytes for IPv4 per RFC 5426
section 3.2.  Restore the old default behaviour of truncating to 1024
bytes.  RFC 5424 specifies no upper limit on the length of forwarded
messages, while for RFC 3164 the limit is 1024 bytes.

Increase MAXLINE to 8192 bytes to correspond to commit 672ef817a192.

Replaced bootfile[] size for MAXPATHLEN used in getbootfile(3) as a
returned value. Using (MAXLINE+1) as a size for bootfile[] is excessive.

PR:		241937
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D27206
2021-03-23 12:49:58 -04:00
John-Mark Gurney 37d8e9a326 fix up documentation/comments: processname is not defined, but programname
is..

a couple other minor documentation fixes that igor caught...

MFC after:	1 week
2020-12-10 23:23:42 +00:00
Gordon Bergling cbf541311c syslog.conf(5): Fix a few mandoc warnings
- new sentence, new line
- skipping paragraph macro: Pp at the end of Sh
2020-11-20 16:50:52 +00:00
Cy Schubert ce558a3f33 Fix build post-r367455.
MFC after:	2 weeks
X-MFC with:	r367455
2020-11-07 19:17:37 +00:00
Bryan Drewery 9470af395f syslogd: Stop trying to send remote messages through special sockets
Specifically this was causing the /dev/klog fd and the signal pipe
handling fd to get a sendmsg(2) called on them and always returned
[ENOTSOCK].

r310350 combined these sockets into the main socket list and properly
skipped AF_UNSPEC at the sendmsg(2) call but later in r344739 it was
broken such that these special sockets were no longer excluded since
the AF_UNSPEC check specifically excluded these special sockets. Only
these special sockets have sl_sa = NULL. The sl_family checks should
be redundant now but are left in case of future changes so the intent
is clearer.

MFC after:	2 weeks
2020-11-07 17:18:44 +00:00