Bug 202190 - newsyslog include processing tries to parse directories as files
Summary: newsyslog include processing tries to parse directories as files
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.2-STABLE
Hardware: i386 Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2015-08-09 01:13 UTC by Gregory Neil Shapiro
Modified: 2020-08-01 04:40 UTC (History)
0 users

See Also:

newsyslog.c patch to skip directories for includes (572 bytes, patch)
2015-08-09 01:13 UTC, Gregory Neil Shapiro
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gregory Neil Shapiro freebsd_committer 2015-08-09 01:13:25 UTC
Created attachment 159681 [details]
newsyslog.c patch to skip directories for includes

If a directory exists under /etc/newsyslog.conf.d/ or /usr/local/etc/newsyslog.conf.d/, newsyslog tries to parse the directory as a file:

# grep include /etc/newsyslog.conf
# rotated, then the entry for that file should include the 'N' flag.
<include> /etc/newsyslog.conf.d/*
<include> /usr/local/etc/newsyslog.conf.d/*
# ls -al /etc/newsyslog.conf.d/
total 10
drwxr-xr-x   3 root  wheel   512 Aug  8 18:05 .
drwxr-xr-x  25 root  wheel  2560 Aug  8 10:42 ..
drwxr-xr-x   2 root  wheel   512 Aug  7 23:44 CVS
-rw-r--r--   1 root  wheel   190 Aug  7 20:01 local.conf
# /usr/sbin/newsyslog
newsyslog: malformed line (missing fields):

The attached patch skips directories when including files.

If for some reason, this change isn't desirable, a workaround is to change the default /etc/newsyslog.conf to only include configuration files instead of all files by replacing:

<include> /etc/newsyslog.conf.d/*
<include> /usr/local/etc/newsyslog.conf.d/*


<include> /etc/newsyslog.conf.d/*.conf
<include> /usr/local/etc/newsyslog.conf.d/*.conf
Comment 1 Gregory Neil Shapiro freebsd_committer 2020-08-01 04:40:06 UTC
This was fixed:

Revision 340318 - (view) (download) (annotate) - [select for diffs]
Modified Sat Nov 10 10:46:38 2018 UTC (20 months, 3 weeks ago) by woodsb02
File length: 1664 byte(s)
Diff to previous 340253
newsyslog.conf: Restrict included files in default config to [!.]*.conf

The new default config will only include files from the following
directories which end with '.conf' and do not beginning with a '.'
- /etc/newsyslog.conf.d/
- /usr/local/etc/newsyslog.conf.d/

This matches the syslog.conf(5) functionality, and also prevents '.sample' or
'.pkgnew' files being included. This is important for ports which install files
in /usr/local/etc/newsyslog.conf.d/ and also for pkgbase.

Approved by:	eadler
Approved by:	bapt
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D17086