From d9b0c77d3e719d4c08361e62f3b067228c30f6a9 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 16 Apr 2008 15:27:53 +0200 Subject: some more cleanup reduced dependencies, moved non-runtime files to its own directory except for some whom's status is unclear --- tools/omusrmsg.c | 352 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 352 insertions(+) create mode 100644 tools/omusrmsg.c (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c new file mode 100644 index 00000000..42d3291d --- /dev/null +++ b/tools/omusrmsg.c @@ -0,0 +1,352 @@ +/* omusrmsg.c + * This is the implementation of the build-in output module for sending + * user messages. + * + * NOTE: read comments in module-template.h to understand how this file + * works! + * + * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c) + * This file is under development and has not yet arrived at being fully + * self-contained and a real object. So far, it is mostly an excerpt + * of the "old" message code without any modifications. However, it + * helps to have things at the right place one we go to the meat of it. + * + * Copyright 2007 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rsyslog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Rsyslog. If not, see . + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ +#include "config.h" +#include "rsyslog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if HAVE_FCNTL_H +#include +#else +#include +#endif +#if HAVE_PATHS_H +#include +#endif +#include "srUtils.h" +#include "stringbuf.h" +#include "syslogd-types.h" +#include "syslogd.h" +#include "omusrmsg.h" +#include "module-template.h" +#include "errmsg.h" + + +/* portability: */ +#ifndef _PATH_DEV +# define _PATH_DEV "/dev/" +#endif + + +MODULE_TYPE_OUTPUT + +/* internal structures + */ +DEF_OMOD_STATIC_DATA +DEFobjCurrIf(errmsg) + +typedef struct _instanceData { + int bIsWall; /* 1- is wall, 0 - individual users */ + char uname[MAXUNAMES][UNAMESZ+1]; +} instanceData; + + +BEGINcreateInstance +CODESTARTcreateInstance +ENDcreateInstance + + +BEGINisCompatibleWithFeature +CODESTARTisCompatibleWithFeature + if(eFeat == sFEATURERepeatedMsgReduction) + iRet = RS_RET_OK; +ENDisCompatibleWithFeature + + +BEGINfreeInstance +CODESTARTfreeInstance + /* TODO: free the instance pointer (currently a leak, will go away) */ +ENDfreeInstance + + +BEGINdbgPrintInstInfo + register int i; +CODESTARTdbgPrintInstInfo + for (i = 0; i < MAXUNAMES && *pData->uname[i]; i++) + dbgprintf("%s, ", pData->uname[i]); +ENDdbgPrintInstInfo + + +static jmp_buf ttybuf; + +static void endtty() +{ + longjmp(ttybuf, 1); +} + +/** + * BSD setutent/getutent() replacement routines + * The following routines emulate setutent() and getutent() under + * BSD because they are not available there. We only emulate what we actually + * need! rgerhards 2005-03-18 + */ +#ifdef OS_BSD +static FILE *BSD_uf = NULL; +void setutent(void) +{ + assert(BSD_uf == NULL); + if ((BSD_uf = fopen(_PATH_UTMP, "r")) == NULL) { + errmsg.LogError(NO_ERRCODE, "%s", _PATH_UTMP); + return; + } +} + +struct utmp* getutent(void) +{ + static struct utmp st_utmp; + + if(fread((char *)&st_utmp, sizeof(st_utmp), 1, BSD_uf) != 1) + return NULL; + + return(&st_utmp); +} + +void endutent(void) +{ + fclose(BSD_uf); + BSD_uf = NULL; +} +#endif /* #ifdef OS_BSD */ + + +/* + * WALLMSG -- Write a message to the world at large + * + * Write the specified message to either the entire + * world, or a list of approved users. + * + * rgerhards, 2005-10-19: applying the following sysklogd patch: + * Tue May 4 16:52:01 CEST 2004: Solar Designer + * Adjust the size of a variable to prevent a buffer overflow + * should _PATH_DEV ever contain something different than "/dev/". + */ +static rsRetVal wallmsg(uchar* pMsg, instanceData *pData) +{ + + char p[sizeof(_PATH_DEV) + UNAMESZ]; + register int i; + int ttyf; + static int reenter = 0; + struct utmp ut; + struct utmp *uptr; + struct sigaction sigAct; + + assert(pMsg != NULL); + + if (reenter++) + return RS_RET_OK; + + /* open the user login file */ + setutent(); + + /* + * Might as well fork instead of using nonblocking I/O + * and doing notty(). + */ + if (fork() == 0) { + memset(&sigAct, 0, sizeof(sigAct)); + sigemptyset(&sigAct.sa_mask); + sigAct.sa_handler = SIG_DFL; + sigaction(SIGTERM, &sigAct, NULL); + alarm(0); + +# ifdef SIGTTOU + sigAct.sa_handler = SIG_DFL; + sigaction(SIGTERM, &sigAct, NULL); +# endif + /* It is save to call sigprocmask here, as we are now executing the child (no threads) */ + sigprocmask(SIG_SETMASK, &sigAct.sa_mask, NULL); + /* TODO: find a way to limit the max size of the message. hint: this + * should go into the template! + */ + + /* rgerhards 2005-10-24: HINT: this code might be run in a seperate thread + * instead of a seperate process once we have multithreading... + */ + + /* scan the user login file */ + while ((uptr = getutent())) { + memcpy(&ut, uptr, sizeof(ut)); + /* is this slot used? */ + if (ut.ut_name[0] == '\0') + continue; +#ifndef OS_BSD + if (ut.ut_type != USER_PROCESS) + continue; +#endif + if (!(strncmp (ut.ut_name,"LOGIN", 6))) /* paranoia */ + continue; + + /* should we send the message to this user? */ + if (pData->bIsWall == 0) { + for (i = 0; i < MAXUNAMES; i++) { + if (!pData->uname[i][0]) { + i = MAXUNAMES; + break; + } + if (strncmp(pData->uname[i], + ut.ut_name, UNAMESZ) == 0) + break; + } + if (i >= MAXUNAMES) + continue; + } + + /* compute the device name */ + strcpy(p, _PATH_DEV); + strncat(p, ut.ut_line, UNAMESZ); + + if (setjmp(ttybuf) == 0) { + sigAct.sa_handler = endtty; + sigaction(SIGALRM, &sigAct, NULL); + (void) alarm(15); + /* open the terminal */ + ttyf = open(p, O_WRONLY|O_NOCTTY); + if (ttyf >= 0) { + struct stat statb; + + if (fstat(ttyf, &statb) == 0 && + (statb.st_mode & S_IWRITE)) { + (void) write(ttyf, pMsg, strlen((char*)pMsg)); + } + close(ttyf); + ttyf = -1; + } + } + (void) alarm(0); + } + exit(0); /* "good" exit - this terminates the child forked just for message delivery */ + } + /* close the user login file */ + endutent(); + reenter = 0; + return RS_RET_OK; +} + + +BEGINtryResume +CODESTARTtryResume +ENDtryResume + +BEGINdoAction +CODESTARTdoAction + dbgprintf("\n"); + iRet = wallmsg(ppString[0], pData); +ENDdoAction + + +BEGINparseSelectorAct + uchar *q; + int i; +CODESTARTparseSelectorAct +CODE_STD_STRING_REQUESTparseSelectorAct(1) + + /* User names must begin with a gnu e-regex: + * [a-zA-Z0-9_.] + * plus '*' for wall + */ + if (!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') + || (*p >= '0' && *p <= '9') || *p == '_' || *p == '.' || *p == '*')) + ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED); + + if((iRet = createInstance(&pData)) != RS_RET_OK) + goto finalize_it; + + + if(*p == '*') { /* wall */ + dbgprintf("write-all"); + ++p; /* eat '*' */ + pData->bIsWall = 1; /* write to all users */ + if((iRet = cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (uchar*) " WallFmt")) + != RS_RET_OK) + goto finalize_it; + } else { + /* everything else beginning with the regex above + * is currently treated as a user name + * TODO: is this portable? + */ + dbgprintf("users: %s\n", p); /* ASP */ + pData->bIsWall = 0; /* write to individual users */ + for (i = 0; i < MAXUNAMES && *p && *p != ';'; i++) { + for (q = p; *q && *q != ',' && *q != ';'; ) + q++; + (void) strncpy((char*) pData->uname[i], (char*) p, UNAMESZ); + if ((q - p) > UNAMESZ) + pData->uname[i][UNAMESZ] = '\0'; + else + pData->uname[i][q - p] = '\0'; + while (*q == ',' || *q == ' ') + q++; + p = q; + } + /* done, on to the template + * TODO: we need to handle the case where i >= MAXUNAME! + */ + if((iRet = cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (uchar*)" StdUsrMsgFmt")) + != RS_RET_OK) + goto finalize_it; + } +CODE_STD_FINALIZERparseSelectorAct +ENDparseSelectorAct + + +BEGINmodExit +CODESTARTmodExit +ENDmodExit + + +BEGINqueryEtryPt +CODESTARTqueryEtryPt +CODEqueryEtryPt_STD_OMOD_QUERIES +ENDqueryEtryPt + + +BEGINmodInit(UsrMsg) +CODESTARTmodInit + *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ +CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); +ENDmodInit + +/* + * vi:set ai: + */ -- cgit v1.2.3 From 06001e951f5b5d0a7919c61057bc7a87b9eb8cba Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 4 Jul 2008 10:17:31 +0200 Subject: rewriten omusrmsg to no longer fork() a new process for sending messages this caused some problems with the threading model, e.g. zombies. Also, it was far less optimal than it is now. --- tools/omusrmsg.c | 188 ++++++++++++++++++++++++------------------------------- 1 file changed, 81 insertions(+), 107 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 42d3291d..830bbc87 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -11,7 +11,18 @@ * of the "old" message code without any modifications. However, it * helps to have things at the right place one we go to the meat of it. * - * Copyright 2007 Rainer Gerhards and Adiscon GmbH. + * Copyright 2007, 2008 Rainer Gerhards and Adiscon GmbH. + * + * rgerhards, 2008-07-04 (happy Independence Day!): rsyslog inherited the + * wall functionality from sysklogd. Sysklogd was single-threaded and could + * not afford to spent a lot of time inside a single action. Thus, it forked + * off a new process to do the wall. In rsyslog, however, this creates some + * grief with the threading model. Also, we do not really need to de-couple + * processing, because we have ample ways to do it in rsyslog. Plus, the + * default main message queue will care for a somewhat longer execution time. + * So in short, the real fix to the problem is an architecture change. From + * now on, we will not fork off a new process but rather do the notification + * within the current one. This also reduces system overhead. * * This file is part of rsyslog. * @@ -43,7 +54,7 @@ #include #include #include -#include +#include #if HAVE_FCNTL_H #include #else @@ -106,13 +117,6 @@ CODESTARTdbgPrintInstInfo ENDdbgPrintInstInfo -static jmp_buf ttybuf; - -static void endtty() -{ - longjmp(ttybuf, 1); -} - /** * BSD setutent/getutent() replacement routines * The following routines emulate setutent() and getutent() under @@ -148,8 +152,7 @@ void endutent(void) #endif /* #ifdef OS_BSD */ -/* - * WALLMSG -- Write a message to the world at large +/* WALLMSG -- Write a message to the world at large * * Write the specified message to either the entire * world, or a list of approved users. @@ -158,108 +161,86 @@ void endutent(void) * Tue May 4 16:52:01 CEST 2004: Solar Designer * Adjust the size of a variable to prevent a buffer overflow * should _PATH_DEV ever contain something different than "/dev/". + * rgerhards, 2008-07-04: changing the function to no longer use fork() but + * continue run on its thread instead. */ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData) { + uchar szErr[512]; char p[sizeof(_PATH_DEV) + UNAMESZ]; register int i; + int errnoSave; int ttyf; - static int reenter = 0; + int wrRet; struct utmp ut; struct utmp *uptr; - struct sigaction sigAct; + struct stat statb; + DEFiRet; assert(pMsg != NULL); - if (reenter++) - return RS_RET_OK; - /* open the user login file */ setutent(); - /* - * Might as well fork instead of using nonblocking I/O - * and doing notty(). - */ - if (fork() == 0) { - memset(&sigAct, 0, sizeof(sigAct)); - sigemptyset(&sigAct.sa_mask); - sigAct.sa_handler = SIG_DFL; - sigaction(SIGTERM, &sigAct, NULL); - alarm(0); - -# ifdef SIGTTOU - sigAct.sa_handler = SIG_DFL; - sigaction(SIGTERM, &sigAct, NULL); -# endif - /* It is save to call sigprocmask here, as we are now executing the child (no threads) */ - sigprocmask(SIG_SETMASK, &sigAct.sa_mask, NULL); - /* TODO: find a way to limit the max size of the message. hint: this - * should go into the template! - */ - - /* rgerhards 2005-10-24: HINT: this code might be run in a seperate thread - * instead of a seperate process once we have multithreading... - */ - - /* scan the user login file */ - while ((uptr = getutent())) { - memcpy(&ut, uptr, sizeof(ut)); - /* is this slot used? */ - if (ut.ut_name[0] == '\0') - continue; + /* scan the user login file */ + while((uptr = getutent())) { + memcpy(&ut, uptr, sizeof(ut)); + /* is this slot used? */ + if(ut.ut_name[0] == '\0') + continue; #ifndef OS_BSD - if (ut.ut_type != USER_PROCESS) - continue; + if(ut.ut_type != USER_PROCESS) + continue; #endif - if (!(strncmp (ut.ut_name,"LOGIN", 6))) /* paranoia */ - continue; - - /* should we send the message to this user? */ - if (pData->bIsWall == 0) { - for (i = 0; i < MAXUNAMES; i++) { - if (!pData->uname[i][0]) { - i = MAXUNAMES; - break; - } - if (strncmp(pData->uname[i], - ut.ut_name, UNAMESZ) == 0) - break; + if(!(strncmp (ut.ut_name,"LOGIN", 6))) /* paranoia */ + continue; + + /* should we send the message to this user? */ + if(pData->bIsWall == 0) { + for(i = 0; i < MAXUNAMES; i++) { + if(!pData->uname[i][0]) { + i = MAXUNAMES; + break; } - if (i >= MAXUNAMES) - continue; + if(strncmp(pData->uname[i], ut.ut_name, UNAMESZ) == 0) + break; } + if(i == MAXUNAMES) /* user not found? */ + continue; /* on to next user! */ + } - /* compute the device name */ - strcpy(p, _PATH_DEV); - strncat(p, ut.ut_line, UNAMESZ); - - if (setjmp(ttybuf) == 0) { - sigAct.sa_handler = endtty; - sigaction(SIGALRM, &sigAct, NULL); - (void) alarm(15); - /* open the terminal */ - ttyf = open(p, O_WRONLY|O_NOCTTY); - if (ttyf >= 0) { - struct stat statb; - - if (fstat(ttyf, &statb) == 0 && - (statb.st_mode & S_IWRITE)) { - (void) write(ttyf, pMsg, strlen((char*)pMsg)); - } - close(ttyf); - ttyf = -1; + /* compute the device name */ + strcpy(p, _PATH_DEV); + strncat(p, ut.ut_line, UNAMESZ); + + /* we must be careful when writing to the terminal. A terminal may block + * (for example, a user has pressed -s). In that case, we can not + * wait indefinitely. So we need to use non-blocking I/O. In case we would + * block, we simply do not send the message, because that's the best we can + * do. -- rgerhards, 2008-07-04 + */ + + /* open the terminal */ + if((ttyf = open(p, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) { + if(fstat(ttyf, &statb) == 0 && (statb.st_mode & S_IWRITE)) { + wrRet = write(ttyf, pMsg, strlen((char*)pMsg)); + if(Debug && wrRet == -1) { + /* we record the state to the debug log */ + errnoSave = errno; + rs_strerror_r(errno, (char*)szErr, sizeof(szErr)); + dbgprintf("write to terminal '%s' failed with [%d]:%s\n", + p, errnoSave, szErr); } } - (void) alarm(0); + close(ttyf); + ttyf = -1; } - exit(0); /* "good" exit - this terminates the child forked just for message delivery */ } + /* close the user login file */ endutent(); - reenter = 0; - return RS_RET_OK; + RETiRet; } @@ -279,30 +260,24 @@ BEGINparseSelectorAct int i; CODESTARTparseSelectorAct CODE_STD_STRING_REQUESTparseSelectorAct(1) + /* User names must begin with a gnu e-regex: + * [a-zA-Z0-9_.] + * plus '*' for wall + */ + if(!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') + || (*p >= '0' && *p <= '9') || *p == '_' || *p == '.' || *p == '*')) + ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED); - /* User names must begin with a gnu e-regex: - * [a-zA-Z0-9_.] - * plus '*' for wall - */ - if (!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') - || (*p >= '0' && *p <= '9') || *p == '_' || *p == '.' || *p == '*')) - ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED); - - if((iRet = createInstance(&pData)) != RS_RET_OK) - goto finalize_it; - + CHKiRet(createInstance(&pData)); if(*p == '*') { /* wall */ dbgprintf("write-all"); ++p; /* eat '*' */ pData->bIsWall = 1; /* write to all users */ - if((iRet = cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (uchar*) " WallFmt")) - != RS_RET_OK) - goto finalize_it; + CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (uchar*) " WallFmt")); } else { - /* everything else beginning with the regex above - * is currently treated as a user name - * TODO: is this portable? + /* everything else beginning with the regex above + * is currently treated as a user name -- TODO: is this portable? */ dbgprintf("users: %s\n", p); /* ASP */ pData->bIsWall = 0; /* write to individual users */ @@ -322,7 +297,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) * TODO: we need to handle the case where i >= MAXUNAME! */ if((iRet = cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (uchar*)" StdUsrMsgFmt")) - != RS_RET_OK) + != RS_RET_OK) goto finalize_it; } CODE_STD_FINALIZERparseSelectorAct @@ -347,6 +322,5 @@ CODEmodInit_QueryRegCFSLineHdlr CHKiRet(objUse(errmsg, CORE_COMPONENT)); ENDmodInit -/* - * vi:set ai: +/* vim:set ai: */ -- cgit v1.2.3 From e3d9843c85b1dfddabc937ac6ccb4057d626bf03 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 12 Jun 2009 11:47:00 +0200 Subject: re-enabled pipe, tty and console in omfile ... by moving code to stream.c. Thanks to the new design, new cases are not really needed, resulting in cleaner code. I also did a cleanup of header file usage as a side-activity. --- tools/omusrmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 830bbc87..499a11dd 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -66,7 +66,7 @@ #include "srUtils.h" #include "stringbuf.h" #include "syslogd-types.h" -#include "syslogd.h" +#include "conf.h" #include "omusrmsg.h" #include "module-template.h" #include "errmsg.h" -- cgit v1.2.3 From f12a1995e42d098217fef22cba6e7158ed76e635 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sun, 28 Feb 2010 18:33:08 +0100 Subject: bugfix: fixed problem that caused compilation on FreeBSD 9.0 to fail. bugtracker: http://bugzilla.adiscon.com/show_bug.cgi?id=181 Thanks to Christiano for reporting. --- tools/omusrmsg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 499a11dd..fe3fb4d4 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -50,7 +50,11 @@ #include #include #include -#include +#ifdef HAVE_UTMP_X_H +# include +#else +# include +#endif #include #include #include -- cgit v1.2.3 From 7b654060b624d976116d959f4cf799f940c00f0a Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 1 Mar 2010 07:57:24 +0100 Subject: fixed typo that (could have) caused compilation fail under FreeBSD Note that I now also prefer to use utmp.h if it is present - this seems to be much better under Linux. --- tools/omusrmsg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index fe3fb4d4..a89297d7 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -50,10 +50,10 @@ #include #include #include -#ifdef HAVE_UTMP_X_H -# include -#else +#ifdef HAVE_UTMP_H # include +#else +# include #endif #include #include -- cgit v1.2.3 From d7755dd3dc5a653adff79a83b6115f872509b3d9 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Tue, 2 Mar 2010 07:37:48 +0100 Subject: solved compile problems on FreeBSD 9.0 (those caused by utmpx.h) Signed-off-by: Rainer Gerhards --- tools/omusrmsg.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index a89297d7..9279028c 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -52,8 +52,13 @@ #include #ifdef HAVE_UTMP_H # include +# define STRUCTUTMP struct utmp #else # include +# define _PATH_UTMP "/var/run/utx.active" +# define _PATH_WTMP "/var/log/utx.log" +# define _PATH_LASTLOG "/var/log/utx.lastlogin" +# define STRUCTUTMP struct utmpx #endif #include #include @@ -138,9 +143,9 @@ void setutent(void) } } -struct utmp* getutent(void) +STRUCTUTMP* getutent(void) { - static struct utmp st_utmp; + static STRUCTUTMP st_utmp; if(fread((char *)&st_utmp, sizeof(st_utmp), 1, BSD_uf) != 1) return NULL; @@ -177,8 +182,8 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData) int errnoSave; int ttyf; int wrRet; - struct utmp ut; - struct utmp *uptr; + STRUCTUTMP ut; + STRUCTUTMP *uptr; struct stat statb; DEFiRet; @@ -191,13 +196,21 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData) while((uptr = getutent())) { memcpy(&ut, uptr, sizeof(ut)); /* is this slot used? */ - if(ut.ut_name[0] == '\0') + + char UTNAME[MAXUNAMES]; +#ifdef HAVE_UTMP_H + strcpy(UTNAME,ut.ut_name); +#else + strcpy(UTNAME,ut.ut_user); +#endif + + if(UTNAME[0] == '\0') continue; #ifndef OS_BSD if(ut.ut_type != USER_PROCESS) continue; #endif - if(!(strncmp (ut.ut_name,"LOGIN", 6))) /* paranoia */ + if(!(strncmp (UTNAME,"LOGIN", 6))) /* paranoia */ continue; /* should we send the message to this user? */ @@ -207,7 +220,7 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData) i = MAXUNAMES; break; } - if(strncmp(pData->uname[i], ut.ut_name, UNAMESZ) == 0) + if(strncmp(pData->uname[i], UTNAME, UNAMESZ) == 0) break; } if(i == MAXUNAMES) /* user not found? */ -- cgit v1.2.3 From 4c060687cf877e4c7faee02f33c219e5f6c8f8f6 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 4 Mar 2010 09:51:28 +0100 Subject: streamlined BSD utmpx.h patch Signed-off-by: Rainer Gerhards --- tools/omusrmsg.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 9279028c..e788a006 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -53,12 +53,11 @@ #ifdef HAVE_UTMP_H # include # define STRUCTUTMP struct utmp +# define UTNAME ut_name #else # include -# define _PATH_UTMP "/var/run/utx.active" -# define _PATH_WTMP "/var/log/utx.log" -# define _PATH_LASTLOG "/var/log/utx.lastlogin" # define STRUCTUTMP struct utmpx +# define UTNAME ut_user #endif #include #include @@ -133,6 +132,12 @@ ENDdbgPrintInstInfo * need! rgerhards 2005-03-18 */ #ifdef OS_BSD +/* Since version 900007, FreeBSD has a POSIX compliant */ +#if defined(__FreeBSD__) && (__FreeBSD_version >= 900007) +# define setutent(void) setutxent(void) +# define getutent(void) getutxent(void) +# define endutent(void) endutxent(void) +#else static FILE *BSD_uf = NULL; void setutent(void) { @@ -158,6 +163,7 @@ void endutent(void) fclose(BSD_uf); BSD_uf = NULL; } +#endif /* if defined(__FreeBSD__) */ #endif /* #ifdef OS_BSD */ @@ -196,21 +202,13 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData) while((uptr = getutent())) { memcpy(&ut, uptr, sizeof(ut)); /* is this slot used? */ - - char UTNAME[MAXUNAMES]; -#ifdef HAVE_UTMP_H - strcpy(UTNAME,ut.ut_name); -#else - strcpy(UTNAME,ut.ut_user); -#endif - - if(UTNAME[0] == '\0') + if(ut.UTNAME[0] == '\0') continue; #ifndef OS_BSD if(ut.ut_type != USER_PROCESS) continue; #endif - if(!(strncmp (UTNAME,"LOGIN", 6))) /* paranoia */ + if(!(strncmp (ut.UTNAME,"LOGIN", 6))) /* paranoia */ continue; /* should we send the message to this user? */ @@ -220,7 +218,7 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData) i = MAXUNAMES; break; } - if(strncmp(pData->uname[i], UTNAME, UNAMESZ) == 0) + if(strncmp(pData->uname[i], ut.UTNAME, UNAMESZ) == 0) break; } if(i == MAXUNAMES) /* user not found? */ -- cgit v1.2.3 From d18b238f16a7ff4dbb998314b6d76ffb8b2acf59 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 27 Jul 2010 09:44:35 +0200 Subject: milestone commit: output plugin interface changes (may NOT run) The output interface has been changed, but we do not yet utilize the new interface. Also, it looks like a regression was introduced. But before hunting it down, I'd like to make a commit (what also easys the regresion hunt). --- tools/omusrmsg.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index e788a006..8c556f51 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -98,6 +98,16 @@ typedef struct _instanceData { char uname[MAXUNAMES][UNAMESZ+1]; } instanceData; +typedef struct configSettings_s { + EMPTY_STRUCT +} configSettings_t; + +SCOPING_SUPPORT; /* must be set AFTER configSettings_t is defined */ + +BEGINinitConfVars /* (re)set config variables to default values */ +CODESTARTinitConfVars +ENDinitConfVars + BEGINcreateInstance CODESTARTcreateInstance -- cgit v1.2.3 From d460c1cd5d3c13ddc70f1d21ae4befa35b1ac627 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 27 Jul 2010 11:38:25 +0200 Subject: fixed regression from last commit config variables were not properly initialized --- tools/omusrmsg.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 8c556f51..ec4bf6d0 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -342,6 +342,7 @@ ENDqueryEtryPt BEGINmodInit(UsrMsg) CODESTARTmodInit +SCOPINGmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr CHKiRet(objUse(errmsg, CORE_COMPONENT)); -- cgit v1.2.3 From 0a24b3afc093e16038da170458e2ecb68b363bdd Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 19 Oct 2010 12:39:48 +0200 Subject: fixing some compile problems on FreeBSD --- tools/omusrmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index e788a006..e61751dc 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -143,7 +143,7 @@ void setutent(void) { assert(BSD_uf == NULL); if ((BSD_uf = fopen(_PATH_UTMP, "r")) == NULL) { - errmsg.LogError(NO_ERRCODE, "%s", _PATH_UTMP); + errmsg.LogError(0, NO_ERRCODE, "%s", _PATH_UTMP); return; } } -- cgit v1.2.3 From 371a8eec29fa25bbf58f4b1f0d7e3bf4c3ad6329 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 16 Dec 2010 12:57:55 +0100 Subject: some cleanup based on clang static analyzer results --- tools/omusrmsg.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index e61751dc..768baca7 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -249,7 +249,6 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData) } } close(ttyf); - ttyf = -1; } } -- cgit v1.2.3 From d1eb6e0edc51a78f3209448e800b25eda50340f2 Mon Sep 17 00:00:00 2001 From: Bojan Smojver Date: Wed, 23 Feb 2011 11:25:43 +0100 Subject: added work-around for bug in gtls, which causes fd leak when using TLS The capability has been added for module to specify that they do not like being unloaded. related bug tracker: http://bugzilla.adiscon.com/show_bug.cgi?id=222 Signed-off-by: Rainer Gerhards --- tools/omusrmsg.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 768baca7..2d99c1e4 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -87,6 +87,7 @@ MODULE_TYPE_OUTPUT +MODULE_TYPE_NOKEEP /* internal structures */ -- cgit v1.2.3 From f09ee69ee1b7f8c098d0720c8e85a6753cc7d342 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 6 Jul 2011 07:52:50 +0200 Subject: added support for the ":omusrmsg:" syntax in configuring user messages --- tools/omusrmsg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 768baca7..44b85bd9 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -278,7 +278,9 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) * [a-zA-Z0-9_.] * plus '*' for wall */ - if(!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') + if(!strncmp((char*) p, ":omusrmsg:", sizeof(":omusrmsg:") - 1)) { + p += sizeof(":omusrmsg:") - 1; /* eat indicator sequence (-1 because of '\0'!) */ + } else if(!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == '_' || *p == '.' || *p == '*')) ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED); -- cgit v1.2.3 From 88fdb0c5ef6a34d28b358c9a50a6b172e25c4ee4 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 6 Jul 2011 08:32:07 +0200 Subject: issue a warning if old omusrmsg action syntax is used --- tools/omusrmsg.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index c737454f..6d46813e 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -281,9 +281,17 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) */ if(!strncmp((char*) p, ":omusrmsg:", sizeof(":omusrmsg:") - 1)) { p += sizeof(":omusrmsg:") - 1; /* eat indicator sequence (-1 because of '\0'!) */ - } else if(!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') - || (*p >= '0' && *p <= '9') || *p == '_' || *p == '.' || *p == '*')) + } else { + if(!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') + || (*p >= '0' && *p <= '9') || *p == '_' || *p == '.' || *p == '*')) { ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED); + } else { + errmsg.LogError(0, RS_RET_OUTDATED_STMT, + "action '%s' treated as ':omusrmsg:%s' - please " + "change syntax, '%s' will not be supported in the future", + p, p, p); + } + } CHKiRet(createInstance(&pData)); -- cgit v1.2.3 From 8cd429f7eeee548ff3d5a4d44daa22c2e5a1cf3a Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 6 Jul 2011 08:39:27 +0200 Subject: issue a warning if old omusrmsg action syntax is used --- tools/omusrmsg.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index d28822ed..3ee01612 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -291,9 +291,17 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) */ if(!strncmp((char*) p, ":omusrmsg:", sizeof(":omusrmsg:") - 1)) { p += sizeof(":omusrmsg:") - 1; /* eat indicator sequence (-1 because of '\0'!) */ - } else if(!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') - || (*p >= '0' && *p <= '9') || *p == '_' || *p == '.' || *p == '*')) + } else { + if(!*p || !((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') + || (*p >= '0' && *p <= '9') || *p == '_' || *p == '.' || *p == '*')) { ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED); + } else { + errmsg.LogError(0, RS_RET_OUTDATED_STMT, + "action '%s' treated as ':omusrmsg:%s' - please " + "change syntax, '%s' will not be supported in the future", + p, p, p); + } + } CHKiRet(createInstance(&pData)); -- cgit v1.2.3 From be804fecf0e383e2b9c4fa646bcd838f1d2545ef Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 21 Jul 2011 19:02:26 +0200 Subject: omusrmsg now supports the new config system --- tools/omusrmsg.c | 166 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 128 insertions(+), 38 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 3ee01612..358b6ce7 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -11,18 +11,7 @@ * of the "old" message code without any modifications. However, it * helps to have things at the right place one we go to the meat of it. * - * Copyright 2007, 2008 Rainer Gerhards and Adiscon GmbH. - * - * rgerhards, 2008-07-04 (happy Independence Day!): rsyslog inherited the - * wall functionality from sysklogd. Sysklogd was single-threaded and could - * not afford to spent a lot of time inside a single action. Thus, it forked - * off a new process to do the wall. In rsyslog, however, this creates some - * grief with the threading model. Also, we do not really need to de-couple - * processing, because we have ample ways to do it in rsyslog. Plus, the - * default main message queue will care for a somewhat longer execution time. - * So in short, the real fix to the problem is an architecture change. From - * now on, we will not fork off a new process but rather do the notification - * within the current one. This also reduces system overhead. + * Copyright 2007-2011 Rainer Gerhards and Adiscon GmbH. * * This file is part of rsyslog. * @@ -49,6 +38,7 @@ #include #include #include +#include #include #ifdef HAVE_UTMP_H # include @@ -88,6 +78,7 @@ MODULE_TYPE_OUTPUT MODULE_TYPE_NOKEEP +MODULE_CNFNAME("omusrmsg") /* internal structures */ @@ -97,6 +88,7 @@ DEFobjCurrIf(errmsg) typedef struct _instanceData { int bIsWall; /* 1- is wall, 0 - individual users */ char uname[MAXUNAMES][UNAMESZ+1]; + uchar *tplName; } instanceData; typedef struct configSettings_s { @@ -105,6 +97,19 @@ typedef struct configSettings_s { SCOPING_SUPPORT; /* must be set AFTER configSettings_t is defined */ + +/* tables for interfacing with the v6 config system */ +/* action (instance) parameters */ +static struct cnfparamdescr actpdescr[] = { + { "users", eCmdHdlrString, CNFPARAM_REQUIRED }, + { "template", eCmdHdlrGetWord, 0 } +}; +static struct cnfparamblk actpblk = + { CNFPARAMBLK_VERSION, + sizeof(actpdescr)/sizeof(struct cnfparamdescr), + actpdescr + }; + BEGINinitConfVars /* (re)set config variables to default values */ CODESTARTinitConfVars ENDinitConfVars @@ -124,7 +129,7 @@ ENDisCompatibleWithFeature BEGINfreeInstance CODESTARTfreeInstance - /* TODO: free the instance pointer (currently a leak, will go away) */ + free(pData->tplName); ENDfreeInstance @@ -280,15 +285,111 @@ CODESTARTdoAction ENDdoAction -BEGINparseSelectorAct - uchar *q; +static inline void +populateUsers(instanceData *pData, es_str_t *usrs) +{ + int i; + int iDst; + es_size_t iUsr; + es_size_t len; + uchar *c; + + len = es_strlen(usrs); + c = es_getBufAddr(usrs); + pData->bIsWall = 0; /* write to individual users */ + iUsr = 0; + for(i = 0 ; i < MAXUNAMES && iUsr < len ; ++i) { + for( iDst = 0 + ; iDst < UNAMESZ && iUsr < len && c[iUsr] != ',' + ; ++iDst, ++iUsr) { + pData->uname[i][iDst] = c[iUsr]; + } + pData->uname[i][iDst] = '\0'; + DBGPRINTF("omusrmsg: send to user '%s'\n", pData->uname[i]); + if(iUsr < len && c[iUsr] != ',') { + errmsg.LogError(0, RS_RET_ERR, "user name '%s...' too long - " + "ignored", pData->uname[i]); + --i; + ++iUsr; + while(iUsr < len && c[iUsr] != ',') + ++iUsr; /* skip to next name */ + } else if(iDst == 0) { + errmsg.LogError(0, RS_RET_ERR, "no user name given - " + "ignored"); + --i; + ++iUsr; + while(iUsr < len && c[iUsr] != ',') + ++iUsr; /* skip to next name */ + } + if(iUsr < len) { + ++iUsr; /* skip "," */ + while(iUsr < len && isspace(c[iUsr])) + ++iUsr; /* skip whitespace */ + } + } + if(i == MAXUNAMES && iUsr != len) { + errmsg.LogError(0, RS_RET_ERR, "omusrmsg supports only up to %d " + "user names in a single action - all others have been ignored", + MAXUNAMES); + } +} + + +static inline void +setInstParamDefaults(instanceData *pData) +{ + pData->bIsWall = 0; + pData->tplName = NULL; +} + +BEGINnewActInst + struct cnfparamvals *pvals; int i; +CODESTARTnewActInst + if((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL) { + ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS); + } + + CHKiRet(createInstance(&pData)); + setInstParamDefaults(pData); + + CODE_STD_STRING_REQUESTparseSelectorAct(1) + for(i = 0 ; i < actpblk.nParams ; ++i) { + if(!pvals[i].bUsed) + continue; + if(!strcmp(actpblk.descr[i].name, "users")) { + if(!es_strbufcmp(pvals[i].val.d.estr, (uchar*)"*", 1)) { + pData->bIsWall = 1; + } else { + populateUsers(pData, pvals[i].val.d.estr); + } + } else if(!strcmp(actpblk.descr[i].name, "template")) { + pData->tplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + } else { + dbgprintf("omusrmsg: program error, non-handled " + "param '%s'\n", actpblk.descr[i].name); + } + } + + if(pData->tplName == NULL) { + CHKiRet(OMSRsetEntry(*ppOMSR, 0, + (uchar*) strdup(pData->bIsWall ? " WallFmt" : " StdUsrMsgFmt"), + OMSR_NO_RQD_TPL_OPTS)); + } else { + CHKiRet(OMSRsetEntry(*ppOMSR, 0, + (uchar*) strdup((char*) pData->tplName), + OMSR_NO_RQD_TPL_OPTS)); + } +CODE_STD_FINALIZERnewActInst + cnfparamvalsDestruct(pvals, &actpblk); +ENDnewActInst + + + +BEGINparseSelectorAct + es_str_t *usrs; CODESTARTparseSelectorAct CODE_STD_STRING_REQUESTparseSelectorAct(1) - /* User names must begin with a gnu e-regex: - * [a-zA-Z0-9_.] - * plus '*' for wall - */ if(!strncmp((char*) p, ":omusrmsg:", sizeof(":omusrmsg:") - 1)) { p += sizeof(":omusrmsg:") - 1; /* eat indicator sequence (-1 because of '\0'!) */ } else { @@ -311,26 +412,14 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) pData->bIsWall = 1; /* write to all users */ CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (uchar*) " WallFmt")); } else { - /* everything else beginning with the regex above - * is currently treated as a user name -- TODO: is this portable? - */ - dbgprintf("users: %s\n", p); /* ASP */ - pData->bIsWall = 0; /* write to individual users */ - for (i = 0; i < MAXUNAMES && *p && *p != ';'; i++) { - for (q = p; *q && *q != ',' && *q != ';'; ) - q++; - (void) strncpy((char*) pData->uname[i], (char*) p, UNAMESZ); - if ((q - p) > UNAMESZ) - pData->uname[i][UNAMESZ] = '\0'; - else - pData->uname[i][q - p] = '\0'; - while (*q == ',' || *q == ' ') - q++; - p = q; + /* everything else is currently treated as a user name */ + usrs = es_newStr(128); + while(*p && *p != ';') { + es_addChar(&usrs, *p); + ++p; } - /* done, on to the template - * TODO: we need to handle the case where i >= MAXUNAME! - */ + populateUsers(pData, usrs); + es_deleteStr(usrs); if((iRet = cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (uchar*)" StdUsrMsgFmt")) != RS_RET_OK) goto finalize_it; @@ -347,6 +436,7 @@ ENDmodExit BEGINqueryEtryPt CODESTARTqueryEtryPt CODEqueryEtryPt_STD_OMOD_QUERIES +CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES ENDqueryEtryPt -- cgit v1.2.3 From d6b6b30c189bf8ea78b59b8b4d3008d1f89ef1b3 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 9 Aug 2011 11:48:52 +0200 Subject: added capability to emit config error location info for warnings otherwise, omusrmsg's warning about new config format was not accompanied by problem location. --- tools/omusrmsg.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 6d46813e..459e5fd6 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -273,6 +273,7 @@ ENDdoAction BEGINparseSelectorAct uchar *q; int i; + int bHadWarning = 0; CODESTARTparseSelectorAct CODE_STD_STRING_REQUESTparseSelectorAct(1) /* User names must begin with a gnu e-regex: @@ -290,6 +291,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) "action '%s' treated as ':omusrmsg:%s' - please " "change syntax, '%s' will not be supported in the future", p, p, p); + bHadWarning = 1; } } @@ -325,6 +327,8 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) != RS_RET_OK) goto finalize_it; } + if(iRet == RS_RET_OK && bHadWarning) + iRet = RS_RET_OK_WARN; CODE_STD_FINALIZERparseSelectorAct ENDparseSelectorAct -- cgit v1.2.3 From e335a65788ccb9cd381dbd28982079a914f4ae4e Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 14 Jan 2012 18:01:12 +0100 Subject: more license analysis & change --- tools/omusrmsg.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 44b85bd9..0b57c83d 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -5,13 +5,10 @@ * NOTE: read comments in module-template.h to understand how this file * works! * - * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c) - * This file is under development and has not yet arrived at being fully - * self-contained and a real object. So far, it is mostly an excerpt - * of the "old" message code without any modifications. However, it - * helps to have things at the right place one we go to the meat of it. + * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c, which at the + * time of the fork from sysklogd was under BSD license) * - * Copyright 2007, 2008 Rainer Gerhards and Adiscon GmbH. + * Copyright 2007-2012 Adiscon GmbH. * * rgerhards, 2008-07-04 (happy Independence Day!): rsyslog inherited the * wall functionality from sysklogd. Sysklogd was single-threaded and could @@ -26,20 +23,19 @@ * * This file is part of rsyslog. * - * Rsyslog is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rsyslog is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Rsyslog. If not, see . - * - * A copy of the GPL can be found in the file "COPYING" in this distribution. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * -or- + * see COPYING.ASL20 in the source distribution + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "config.h" #include "rsyslog.h" -- cgit v1.2.3 From 535d6cf0b8fe2423eee3fd670bc1e944b231e827 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 19 Jan 2012 14:48:40 +0100 Subject: v6.1/2 scoping support removed from plugins --- tools/omusrmsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index 6d6b267a..f8e40594 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -91,7 +91,7 @@ typedef struct configSettings_s { EMPTY_STRUCT } configSettings_t; -SCOPING_SUPPORT; /* must be set AFTER configSettings_t is defined */ +static configSettings_t cs; /* tables for interfacing with the v6 config system */ @@ -442,7 +442,7 @@ ENDqueryEtryPt BEGINmodInit(UsrMsg) CODESTARTmodInit -SCOPINGmodInit +INITLegCnfVars *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr CHKiRet(objUse(errmsg, CORE_COMPONENT)); -- cgit v1.2.3 From b68af9a016c229259ccb259c33e6598a3a77ea35 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 19 Jan 2012 15:41:49 +0100 Subject: cosmetic: remove compiler warnings --- tools/omusrmsg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index f8e40594..ee2bc59f 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -90,8 +90,7 @@ typedef struct _instanceData { typedef struct configSettings_s { EMPTY_STRUCT } configSettings_t; - -static configSettings_t cs; +static configSettings_t __attribute__((unused)) cs; /* tables for interfacing with the v6 config system */ -- cgit v1.2.3 From 532d6994dffd733e8850d3c743a7b791f8d388b1 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 27 Jan 2012 12:05:40 +0100 Subject: ompipe: support for v6 config system added --- tools/omusrmsg.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index ee2bc59f..e57d7ef9 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -380,7 +380,6 @@ CODE_STD_FINALIZERnewActInst ENDnewActInst - BEGINparseSelectorAct es_str_t *usrs; int bHadWarning; -- cgit v1.2.3 From d3173826268b18d38d67525d8d38083176742c8c Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 28 Aug 2012 15:09:56 +0200 Subject: bugfix: omusrsmsg incorrect return state & config warning handling During config file processing, Omusrmsg often incorrectly returned a warning status, even when no warning was present (caused by uninitialized variable). Also, the core handled warning messages incorrectly, and treated them as errors. As a result, omusrmsg (most often) could not properly be loaded. Note that this only occurs with legacy config action syntax. This was a regression caused by an incorrect merge in to the 6.3.x codebase. Thanks to Stefano Mason for alerting us of this bug. --- tools/omusrmsg.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index e57d7ef9..a7df9243 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -385,6 +385,7 @@ BEGINparseSelectorAct int bHadWarning; CODESTARTparseSelectorAct CODE_STD_STRING_REQUESTparseSelectorAct(1) + bHadWarning = 0; if(!strncmp((char*) p, ":omusrmsg:", sizeof(":omusrmsg:") - 1)) { p += sizeof(":omusrmsg:") - 1; /* eat indicator sequence (-1 because of '\0'!) */ } else { -- cgit v1.2.3 From e5ef73eb25c8dda2e19c593ad2fc0a960aa8873b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 1 Nov 2012 17:05:07 +0100 Subject: bugfix: invalid rsyslog-internal macro API use This had no bad effect, because the macro did the same as the one that should have been used. --- tools/omusrmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/omusrmsg.c') diff --git a/tools/omusrmsg.c b/tools/omusrmsg.c index a7df9243..f4cc4094 100644 --- a/tools/omusrmsg.c +++ b/tools/omusrmsg.c @@ -348,7 +348,7 @@ CODESTARTnewActInst CHKiRet(createInstance(&pData)); setInstParamDefaults(pData); - CODE_STD_STRING_REQUESTparseSelectorAct(1) + CODE_STD_STRING_REQUESTnewActInst(1) for(i = 0 ; i < actpblk.nParams ; ++i) { if(!pvals[i].bUsed) continue; -- cgit v1.2.3