From 745cfae6d3231b409d39bf864706421a2c5a3a2c Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 18 Dec 2007 16:19:46 +0000 Subject: applied Michael Biebl's patch to enhance $includeconfig to support wildcard filenames --- ChangeLog | 3 +++ syslogd.c | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 487387b3..e2ef8832 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ --------------------------------------------------------------------------- Version 1.20.2 (rgerhards), 2007-12-?? +- code cleanup +- enhanced $IncludeConfig directive to support wildcard filenames +- changed some multithreading synchronization --------------------------------------------------------------------------- Version 1.20.1 (rgerhards), 2007-12-12 - corrected a debug setting that survived release. Caused TCP connections diff --git a/syslogd.c b/syslogd.c index 0ed4065c..c67e0233 100644 --- a/syslogd.c +++ b/syslogd.c @@ -178,6 +178,10 @@ #include #include #include +#include +#include +#include + #ifndef __sun #endif @@ -3841,24 +3845,44 @@ finalize_it: static rsRetVal doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal) { DEFiRet; - uchar cfgFile[MAXFNAME]; + char pattern[MAXFNAME]; + char *cfgFile; + glob_t cfgFiles; + size_t i = 0; + struct stat fileInfo; assert(pp != NULL); assert(*pp != NULL); - if(getSubString(pp, (char*) cfgFile, sizeof(cfgFile) / sizeof(uchar), ' ') != 0) { + if(getSubString(pp, (char*) pattern, sizeof(pattern) / sizeof(char), ' ') != 0) { logerror("could not extract group name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } - if(*(cfgFile+strlen((char*) cfgFile) - 1) == '/') { - dbgprintf("requested to include directory '%s'\n", cfgFile); - iRet = doIncludeDirectory(cfgFile); - } else { - dbgprintf("Requested to include config file '%s'\n", cfgFile); - iRet = processConfFile(cfgFile); + /* Use GLOB_MARK to append a trailing slash for directories. + * Required by doIncludeDirectory(). + */ + glob(pattern, GLOB_MARK, NULL, &cfgFiles); + + for(i = 0; i < cfgFiles.gl_pathc; i++) { + cfgFile = cfgFiles.gl_pathv[i]; + + if(stat(cfgFile, &fileInfo) != 0) + continue; /* continue with the next file if we can't stat() the file */ + + if(S_ISREG(fileInfo.st_mode)) { /* config file */ + dbgprintf("requested to include config file '%s'\n", cfgFile); + iRet = processConfFile(cfgFile); + } else if(S_ISDIR(fileInfo.st_mode)) { /* config directory */ + dbgprintf("requested to include directory '%s'\n", cfgFile); + iRet = doIncludeDirectory(cfgFile); + } else { /* TODO: shall we handle symlinks or not? */ + dbgprintf("warning: unable to process IncludeConfig directive '%s'\n", cfgFile); + } } + globfree(&cfgFiles); + finalize_it: return iRet; } -- cgit