From 42b3a7a4356006ce64413ef3583f9cae6d27966b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 4 Jul 2007 10:23:53 +0000 Subject: cleaned up some issues with $FileCreateMode --- NEWS | 2 ++ parse.c | 8 ++++++++ parse.h | 1 + syslogd.c | 33 ++++++++++++++++++++++++--------- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 150252ea..53fe9b68 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ Version 1.15.0 (RGer), 2007-07-?? address. - added $umask and $FileCreateMode config file directives - applied a patch from Bartosz Kuzma to compile cleanly under NetBSD +- checks for extra (unexpected) characters in system config file lines + have been added - added IPv6 documentation - was accidently missing from CVS - begun to change char to unsigned char --------------------------------------------------------------------------- diff --git a/parse.c b/parse.c index bf92e00b..0b26b0a2 100644 --- a/parse.c +++ b/parse.c @@ -467,6 +467,14 @@ char parsPeekAtCharAtParsPtr(rsParsObj *pThis) return(*(pThis->pCStr->pBuf + pThis->iCurrPos)); } +/* return the current position inside the parse object. + * rgerhards, 2007-07-04 + */ +int parsGetCurrentPosition(rsParsObj *pThis) +{ + return pThis->iCurrPos; +} + /* * Local variables: diff --git a/parse.h b/parse.h index 63a7d7cd..38e6aadd 100644 --- a/parse.h +++ b/parse.h @@ -80,6 +80,7 @@ rsRetVal rsParsConstructFromSz(rsParsObj **ppThis, unsigned char *psz); rsRetVal rsParsDestruct(rsParsObj *pThis); rsRetVal parsIPv4WithBits(rsParsObj *pThis, unsigned long *pIP, int *pBits); int parsIsAtEndOfParseString(rsParsObj *pThis); +int parsGetCurrentPosition(rsParsObj *pThis); char parsPeekAtCharAtParsPtr(rsParsObj *pThis); #if 0 /* later! - but leave it in in case we need it some day... */ diff --git a/syslogd.c b/syslogd.c index 5fb712aa..6c45434e 100644 --- a/syslogd.c +++ b/syslogd.c @@ -4,6 +4,12 @@ * TODO: * - include a global option for control character replacemet on receive? (not just NUL) * + * Please visit the rsyslog project at + * + * http://www.rsyslog.com + * + * to learn more about it and discuss any questions you may have. + * * Please note that as of now, a lot of the code in this file stems * from the sysklogd project. To learn more over this project, please * visit @@ -678,7 +684,9 @@ struct filed { struct { char f_fname[MAXFNAME]; char bDynamicName; /* 0 - static name, 1 - dynamic name (with properties) */ - char *pCurrName; /* name currently open, if dynamic name */ + unsigned char *pCurrName; /* name currently open, if dynamic name */ + int fCreateMode; /* file creation mode for open() */ + } f_file; } f_un; char f_lasttime[16]; /* time of last occurrence */ @@ -5829,7 +5837,7 @@ int resolveFileSizeLimit(struct filed *f) system(f->f_sizeLimitCmd); f->f_file = open(f->f_un.f_file.f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY, - fCreateMode); + f->f_un.f_file.fCreateMode); actualFileSize = lseek(f->f_file, 0, SEEK_END); if(actualFileSize >= f->f_sizeLimit) { @@ -5859,14 +5867,15 @@ static int prepareDynFile(struct filed *f) dprintf("prepareDynfile(): could not create file name, discarding this reques\n"); return -1; } - if(strcmp((char*) newFileName, f->f_un.f_file.pCurrName)) { + if(strcmp((char*) newFileName, (char*) f->f_un.f_file.pCurrName)) { dprintf("Requested log file different from currently open one - switching.\n"); dprintf("Current file: '%s'\n", f->f_un.f_file.pCurrName); dprintf("New file : '%s'\n", newFileName); close(f->f_file); - f->f_file = open((char*) newFileName, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY, fCreateMode); + f->f_file = open((char*) newFileName, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY, + f->f_un.f_file.fCreateMode); free(f->f_un.f_file.pCurrName); - f->f_un.f_file.pCurrName = (char*) newFileName; + f->f_un.f_file.pCurrName = newFileName; } else { /* we are all set, the log file is already open */ free(newFileName); @@ -6817,6 +6826,7 @@ static rsRetVal addAllowedSenderLine(char* pName, unsigned char** ppRestOfConfLi } /* cleanup */ + *ppRestOfConfLine += parsGetCurrentPosition(pPars); return rsParsDestruct(pPars); #endif /*#ifndef SYSLOG_INET */ } @@ -6989,13 +6999,14 @@ void cfsysline(unsigned char *p) /* now check if we have some extra characters left on the line - that * should not be the case. Whitespace is OK, but everything else should - * trigger a warning (that may be an indication of undesired behaviour. + * trigger a warning (that may be an indication of undesired behaviour). + * An exception, of course, are comments (starting with '#'). * rgerhards, 2007-07-04 */ while(*p && isspace(*p)) ++p; /* skip it */ - if(*p) { /* we have a non-whitespace, so let's complain */ + if(*p && *p != '#') { /* we have a non-whitespace, so let's complain */ snprintf((char*) errMsg, sizeof(errMsg)/sizeof(unsigned char), "error: extra characters in config line ignored: '%s'", p); errno = 0; @@ -8181,8 +8192,10 @@ static rsRetVal cfline(char *line, register struct filed *f) * traditional mode lines. */ cflineParseOutchannel(f, p); + f->f_un.f_file.bDynamicName = 0; + f->f_un.f_file.fCreateMode = fCreateMode; /* preserve current setting */ f->f_file = open(f->f_un.f_file.f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY, - fCreateMode); + f->f_un.f_file.fCreateMode); break; case '?': /* This is much like a regular file handle, but we need to obtain @@ -8200,6 +8213,7 @@ static rsRetVal cfline(char *line, register struct filed *f) if(syncfile) f->f_flags |= SYNC_FILE; f->f_un.f_file.bDynamicName = 1; + f->f_un.f_file.fCreateMode = fCreateMode; /* preserve current setting */ /* we now allocate a single-byte buffer to create an emtpy previous * file name. That way, we do not need to check for an uninitialized * variable when we do the comparison. This saves us some CPU cycles @@ -8233,11 +8247,12 @@ static rsRetVal cfline(char *line, register struct filed *f) if(syncfile) f->f_flags |= SYNC_FILE; f->f_un.f_file.bDynamicName = 0; + f->f_un.f_file.fCreateMode = fCreateMode; /* preserve current setting */ if(f->f_type == F_PIPE) { f->f_file = open(f->f_un.f_file.f_fname, O_RDWR|O_NONBLOCK); } else { f->f_file = open(f->f_un.f_file.f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY, - fCreateMode); + f->f_un.f_file.fCreateMode); } if ( f->f_file < 0 ){ -- cgit