summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-07-31 08:12:11 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-07-31 08:12:11 +0000
commite123f620d3705263777c279ba319acf83eaf928d (patch)
treecba77826f30abd5fb49a61af479b5506a7d6e7c9
parentc135ef6de2355c9b1c9f69a1df41871e55f55cda (diff)
downloadrsyslog-e123f620d3705263777c279ba319acf83eaf928d.tar.gz
rsyslog-e123f620d3705263777c279ba319acf83eaf928d.tar.xz
rsyslog-e123f620d3705263777c279ba319acf83eaf928d.zip
- added doGetInt() to cfsysline.c and adapted dynaFileChaceSize handler to
use it
-rw-r--r--cfsysline.c57
-rw-r--r--cfsysline.h2
-rw-r--r--rsyslog.h3
-rw-r--r--syslogd.c52
4 files changed, 70 insertions, 44 deletions
diff --git a/cfsysline.c b/cfsysline.c
index 8d063b66..5119df02 100644
--- a/cfsysline.c
+++ b/cfsysline.c
@@ -28,6 +28,7 @@
#include <assert.h>
#include <string.h>
#include <errno.h>
+#include <ctype.h>
#include <pwd.h>
#include <grp.h>
@@ -50,10 +51,9 @@ cslCmd_t *pCmdListLast = NULL;
* HINT: check if char is ' and, if so, use 'c' where c may also be things
* like \t etc.
*/
-//static void doControlCharEscPrefix(uchar **pp)
rsRetVal doGetChar(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
{
- rsRetVal iRet = RS_RET_OK;
+ DEFiRet;
assert(pp != NULL);
assert(*pp != NULL);
@@ -80,6 +80,47 @@ finalize_it:
}
+/* Parse a number from the configuration line.
+ * rgerhards, 2007-07-31
+ */
+rsRetVal doGetInt(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
+{
+ uchar *p;
+ DEFiRet;
+ int i;
+
+ assert(pp != NULL);
+ assert(*pp != NULL);
+
+ skipWhiteSpace(pp); /* skip over any whitespace */
+ p = *pp;
+
+ if(!isdigit((int) *p)) {
+ errno = 0;
+ logerror("invalid number");
+ iRet = RS_RET_INVALID_INT;
+ goto finalize_it;
+ }
+
+ /* pull value */
+ for(i = 0 ; *p && isdigit((int) *p) ; ++p)
+ i = i * 10 + *p - '0';
+
+ if(pSetHdlr == NULL) {
+ /* we should set value directly to var */
+ *((int*)pVal) = i;
+ } else {
+ /* we set value via a set function */
+ CHKiRet(pSetHdlr(pVal, i));
+ }
+
+ *pp = p;
+
+finalize_it:
+ return iRet;
+}
+
+
/* Parse and interpet a $FileCreateMode and $umask line. This function
* pulls the creation mode and, if successful, stores it
* into the global variable so that the rest of rsyslogd
@@ -95,7 +136,7 @@ finalize_it:
rsRetVal doFileCreateMode(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
{
uchar *p;
- rsRetVal iRet = RS_RET_OK;
+ DEFiRet;
uchar errMsg[128]; /* for dynamic error messages */
int iVal;
@@ -184,7 +225,7 @@ rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
{
struct group *pgBuf;
struct group gBuf;
- rsRetVal iRet = RS_RET_OK;
+ DEFiRet;
uchar szName[256];
char stringBuf[2048]; /* I hope this is large enough... */
@@ -227,7 +268,7 @@ rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
{
struct passwd *ppwBuf;
struct passwd pwBuf;
- rsRetVal iRet = RS_RET_OK;
+ DEFiRet;
uchar szName[256];
char stringBuf[2048]; /* I hope this is large enough... */
@@ -271,7 +312,7 @@ finalize_it:
rsRetVal doBinaryOptionLine(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal)
{
int iOption;
- rsRetVal iRet = RS_RET_OK;
+ DEFiRet;
assert(pp != NULL);
assert(*pp != NULL);
@@ -312,7 +353,7 @@ rsRetVal cslchDestruct(cslCmdHdlr_t *pThis)
rsRetVal cslchConstruct(cslCmdHdlr_t **ppThis)
{
cslCmdHdlr_t *pThis;
- rsRetVal iRet = RS_RET_OK;
+ DEFiRet;
assert(ppThis != NULL);
if((pThis = calloc(1, sizeof(cslCmdHdlr_t))) == NULL) {
@@ -380,7 +421,7 @@ rsRetVal cslcDestruct(cslCmd_t *pThis)
rsRetVal cslcConstruct(cslCmd_t **ppThis)
{
cslCmd_t *pThis;
- rsRetVal iRet = RS_RET_OK;
+ DEFiRet;
assert(ppThis != NULL);
if((pThis = calloc(1, sizeof(cslCmd_t))) == NULL) {
diff --git a/cfsysline.h b/cfsysline.h
index f03419db..b9349659 100644
--- a/cfsysline.h
+++ b/cfsysline.h
@@ -31,6 +31,7 @@ typedef enum cslCmdHdlrType {
eCmdHdlrGUID,
eCmdHdlrBinary,
eCmdHdlrFileCreateMode,
+ eCmdHdlrInt,
eCmdHdlrFileGetChar
} ecslCmdHdrlType;
@@ -71,5 +72,6 @@ rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
rsRetVal doFileCreateMode(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
rsRetVal doGetChar(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
+rsRetVal doGetInt(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
#endif /* #ifndef CFSYSLINE_H_INCLUDED */
diff --git a/rsyslog.h b/rsyslog.h
index 2badea3c..4a379cd9 100644
--- a/rsyslog.h
+++ b/rsyslog.h
@@ -60,6 +60,8 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
RS_RET_SUSPENDED = -2007, /**< something was suspended, not neccesarily an error */
RS_RET_RQD_TPLOPT_MISSING = -2008,/**< a required template option is missing */
RS_RET_INVALID_VALUE = -2009,/**< some value is invalid (e.g. user-supplied data) */
+ RS_RET_INVALID_INT = -2010,/**< invalid integer */
+ RS_RET_VAL_OUT_OF_RANGE = -2011, /**< value out of range */
RS_RET_OK = 0 /**< operation successful */
};
typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */
@@ -69,6 +71,7 @@ typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */
* the function finalizer always "finalize_it".
*/
#define CHKiRet(code) if((iRet = code) != RS_RET_OK) goto finalize_it
+#define DEFiRet rsRetVal iRet = RS_RET_OK
/** Object ID. These are for internal checking. Each
* object is assigned a specific ID. This is contained in
diff --git a/syslogd.c b/syslogd.c
index 6865a026..05567e44 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -3431,57 +3431,37 @@ static rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine)
}
-/* Parse and interpret a $DynaFileCacheSize line.
- * Parameter **pp has a pointer to the current config line.
- * On exit, it will be updated to the processed position.
- * rgerhards, 2007-07-4 (happy independence day to my US friends!)
+/* set the dynaFile cache size. Does some limit checking.
+ * rgerhards, 2007-07-31
*/
-static void doDynaFileCacheSizeLine(uchar **pp)
+static rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal)
{
- uchar *p;
+ DEFiRet;
uchar errMsg[128]; /* for dynamic error messages */
- int i;
-
- assert(pp != NULL);
- assert(*pp != NULL);
-
- skipWhiteSpace(pp); /* skip over any whitespace */
- p = *pp;
-
- if(!isdigit((int) *p)) {
- snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
- "DynaFileCacheSize invalid, value '%s'.", p);
- errno = 0;
- logerror((char*) errMsg);
- return;
- }
- /* pull value */
- for(i = 0 ; *p && isdigit((int) *p) ; ++p)
- i = i * 10 + *p - '0';
-
- if(i < 1) {
+ if(iNewVal < 1) {
snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
- "DynaFileCacheSize must be greater 0 (%d given), changed to 1.", i);
+ "DynaFileCacheSize must be greater 0 (%d given), changed to 1.", iNewVal);
errno = 0;
logerror((char*) errMsg);
- i = 1;
- } else if(i > 10000) {
+ iRet = RS_RET_VAL_OUT_OF_RANGE;
+ iNewVal = 1;
+ } else if(iNewVal > 10000) {
snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
- "DynaFileCacheSize maximum is 10,000 (%d given), changed to 10,000.", i);
+ "DynaFileCacheSize maximum is 10,000 (%d given), changed to 10,000.", iNewVal);
errno = 0;
logerror((char*) errMsg);
- i = 10000;
+ iRet = RS_RET_VAL_OUT_OF_RANGE;
+ iNewVal = 10000;
}
- iDynaFileCacheSize = i;
- dprintf("DynaFileCacheSize changed to %d.\n", i);
+ iDynaFileCacheSize = iNewVal;
+ dprintf("DynaFileCacheSize changed to %d.\n", iNewVal);
- *pp = p;
+ return iRet;
}
-
/* process a $ModLoad config line.
* As of now, it is a dummy, that will later evolve into the
* loader for plug-ins.
@@ -3621,7 +3601,7 @@ void cfsysline(uchar *p)
} else if(!strcasecmp((char*) szCmd, "filegroup")) {
doGetGID(&p, NULL, &fileGID);
} else if(!strcasecmp((char*) szCmd, "dynafilecachesize")) {
- doDynaFileCacheSizeLine(&p);
+ doGetInt(&p, (void*) setDynaFileCacheSize, NULL);
} else if(!strcasecmp((char*) szCmd, "repeatedmsgreduction")) {
doBinaryOptionLine(&p, NULL, &bReduceRepeatMsgs);
} else if(!strcasecmp((char*) szCmd, "controlcharacterescapeprefix")) {