summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-07-24 06:20:34 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-07-24 06:20:34 +0000
commitd06dafb6768e2bbb4128aa4370fc3dc53fc01056 (patch)
tree01601d24510d0f7bbaba09fd06eebe6e9f1dcbe6
parentf12dd1b777c91d3491505cb2c99feb5987db8edc (diff)
downloadrsyslog-d06dafb6768e2bbb4128aa4370fc3dc53fc01056.tar.gz
rsyslog-d06dafb6768e2bbb4128aa4370fc3dc53fc01056.tar.xz
rsyslog-d06dafb6768e2bbb4128aa4370fc3dc53fc01056.zip
moved selector action parsing for MySQL to ommysql
-rw-r--r--ommysql.c113
-rw-r--r--ommysql.h1
-rw-r--r--syslogd.c90
-rw-r--r--syslogd.h2
4 files changed, 119 insertions, 87 deletions
diff --git a/ommysql.c b/ommysql.c
index 9cacd0bb..fc7075f1 100644
--- a/ommysql.c
+++ b/ommysql.c
@@ -39,6 +39,7 @@
#include "syslogd.h"
#include "syslogd-types.h"
#include "srUtils.h"
+#include "template.h"
#include "ommysql.h"
#include "mysql/mysql.h"
#include "mysql/errmsg.h"
@@ -304,6 +305,118 @@ rsRetVal modInitMySQL(int iIFVersRequested __attribute__((unused)), int *ipIFVer
*pQueryEtryPt = queryEtryPt;
return RS_RET_OK;
}
+
+
+/* try to process a selector action line. Checks if the action
+ * applies to this module and, if so, processed it. If not, it
+ * is left untouched. The driver will then call another module
+ */
+rsRetVal parseSelectorActMySQL(uchar **pp, selector_t *f)
+{
+ uchar *p;
+ rsRetVal iRet = RS_RET_CONFLINE_PROCESSED;
+ int iMySQLPropErr = 0;
+ char szTemplateName[128];
+
+ assert(pp != NULL);
+ assert(f != NULL);
+
+ p = *pp;
+
+ switch (*p)
+ {
+ case '>':
+ /* rger 2004-10-28: added support for MySQL
+ * >server,dbname,userid,password
+ * rgerhards 2005-08-12: changed rsyslogd so that
+ * if no DB is selected and > is used, an error
+ * message is logged.
+ */
+ if(bModMySQLLoaded == 0)
+ logerror("To enable MySQL logging, a \"$ModLoad MySQL\" must be done - accepted for "
+ "the time being, but will fail in future releases.");
+#ifndef WITH_DB
+ f->f_type = F_UNUSED;
+ errno = 0;
+ logerror("write to database action in config file, but rsyslogd compiled without "
+ "database functionality - ignored");
+#else /* WITH_DB defined! */
+ f->f_type = F_MYSQL;
+ f->doAction = doActionMySQL;
+ p++;
+
+ /* Now we read the MySQL connection properties
+ * and verify that the properties are valid.
+ */
+ if(getSubString(&p, f->f_un.f_mysql.f_dbsrv, MAXHOSTNAMELEN+1, ','))
+ iMySQLPropErr++;
+ if(*f->f_un.f_mysql.f_dbsrv == '\0')
+ iMySQLPropErr++;
+ if(getSubString(&p, f->f_un.f_mysql.f_dbname, _DB_MAXDBLEN+1, ','))
+ iMySQLPropErr++;
+ if(*f->f_un.f_mysql.f_dbname == '\0')
+ iMySQLPropErr++;
+ if(getSubString(&p, f->f_un.f_mysql.f_dbuid, _DB_MAXUNAMELEN+1, ','))
+ iMySQLPropErr++;
+ if(*f->f_un.f_mysql.f_dbuid == '\0')
+ iMySQLPropErr++;
+ if(getSubString(&p, f->f_un.f_mysql.f_dbpwd, _DB_MAXPWDLEN+1, ';'))
+ iMySQLPropErr++;
+ if(*p == '\n' || *p == '\0') {
+ /* assign default format if none given! */
+ szTemplateName[0] = '\0';
+ } else {
+ /* we have a template specifier! */
+ cflineParseTemplateName(&p, szTemplateName,
+ sizeof(szTemplateName) / sizeof(char));
+ }
+
+ if(szTemplateName[0] == '\0')
+ strcpy(szTemplateName, " StdDBFmt");
+
+ cflineSetTemplateAndIOV(f, szTemplateName);
+
+ /* we now check if the template was present. If not, we
+ * can abort this run as the selector line has been
+ * disabled. If we don't abort, we'll core dump
+ * below. rgerhards 2005-07-29
+ */
+ if(f->f_type == F_UNUSED)
+ break;
+
+ dprintf(" template '%s'\n", szTemplateName);
+
+ /* If db used, the template have to use the SQL option.
+ This is for your own protection (prevent sql injection). */
+ if (f->f_pTpl->optFormatForSQL == 0) {
+ f->f_type = F_UNUSED;
+ logerror("DB logging disabled. You have to use"
+ " the SQL or stdSQL option in your template!\n");
+ break;
+ }
+
+ /* If we dedect invalid properties, we disable logging,
+ * because right properties are vital at this place.
+ * Retries make no sense.
+ */
+ if (iMySQLPropErr) {
+ f->f_type = F_UNUSED;
+ dprintf("Trouble with MySQL conncetion properties.\n"
+ "MySQL logging disabled.\n");
+ } else {
+ initMySQL(f);
+ }
+#endif /* #ifdef WITH_DB */
+ default:
+ iRet = RS_RET_CONFLINE_UNPROCESSED;
+ break;
+ }
+
+ if(iRet == RS_RET_CONFLINE_PROCESSED)
+ *pp = p;
+ return iRet;
+}
+
#endif /* #ifdef WITH_DB */
/*
* vi:set ai:
diff --git a/ommysql.h b/ommysql.h
index 6b2bcc10..9ecb1333 100644
--- a/ommysql.h
+++ b/ommysql.h
@@ -35,6 +35,7 @@ void closeMySQL(register selector_t *f);
void reInitMySQL(register selector_t *f);
int checkDBErrorState(register selector_t *f);
rsRetVal modInitMySQL(int iIFVersRequested, int *ipIFVersProvided, rsRetVal (**pQueryEtryPt)());
+rsRetVal parseSelectorActMySQL(uchar **pp, selector_t *f);
int doActionMySQL(selector_t *f);
diff --git a/syslogd.c b/syslogd.c
index b59b584d..c2224561 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -360,7 +360,7 @@ static char *ConfFile = _PATH_LOGCONF; /* read-only after startup */
static char *PidFile = _PATH_LOGPID; /* read-only after startup */
char ctty[] = _PATH_CONSOLE; /* this is read-only */
-static int bModMySQLLoaded = 0; /* was a $ModLoad MySQL done? */
+int bModMySQLLoaded = 0; /* was a $ModLoad MySQL done? */
static pid_t myPid; /* our pid for use in self-generated messages, e.g. on startup */
/* mypid is read-only after the initial fork() */
static int debugging_on = 0; /* read-only, except on sig USR1 */
@@ -672,8 +672,6 @@ static int decode(uchar *name, struct code *codetab);
static void sighup_handler();
static void die(int sig);
-static int getSubString(uchar **pSrc, char *pDst, size_t DstSize, char cSep);
-
/* Access functions for the selector_t. These functions are primarily
* necessary to make things thread-safe. Consequently, they are slim
* if we compile without pthread support.
@@ -5039,9 +5037,6 @@ static rsRetVal cfline(char *line, register selector_t *f)
uchar *p;
int syncfile;
rsRetVal iRet;
-#ifdef WITH_DB
- int iMySQLPropErr = 0;
-#endif
dprintf("cfline(%s)", line);
@@ -5116,87 +5111,8 @@ static rsRetVal cfline(char *line, register selector_t *f)
f->f_type = F_DISCARD;
break;
- case '>': /* rger 2004-10-28: added support for MySQL
- * >server,dbname,userid,password
- * rgerhards 2005-08-12: changed rsyslogd so that
- * if no DB is selected and > is used, an error
- * message is logged.
- */
- if(bModMySQLLoaded == 0)
- logerror("To enable MySQL logging, a \"$ModLoad MySQL\" must be done - accepted for "
- "the time being, but will fail in future releases.");
-#ifndef WITH_DB
- f->f_type = F_UNUSED;
- errno = 0;
- logerror("write to database action in config file, but rsyslogd compiled without "
- "database functionality - ignored");
-#else /* WITH_DB defined! */
- f->f_type = F_MYSQL;
- f->doAction = doActionMySQL;
- p++;
-
- /* Now we read the MySQL connection properties
- * and verify that the properties are valid.
- */
- if(getSubString(&p, f->f_un.f_mysql.f_dbsrv, MAXHOSTNAMELEN+1, ','))
- iMySQLPropErr++;
- if(*f->f_un.f_mysql.f_dbsrv == '\0')
- iMySQLPropErr++;
- if(getSubString(&p, f->f_un.f_mysql.f_dbname, _DB_MAXDBLEN+1, ','))
- iMySQLPropErr++;
- if(*f->f_un.f_mysql.f_dbname == '\0')
- iMySQLPropErr++;
- if(getSubString(&p, f->f_un.f_mysql.f_dbuid, _DB_MAXUNAMELEN+1, ','))
- iMySQLPropErr++;
- if(*f->f_un.f_mysql.f_dbuid == '\0')
- iMySQLPropErr++;
- if(getSubString(&p, f->f_un.f_mysql.f_dbpwd, _DB_MAXPWDLEN+1, ';'))
- iMySQLPropErr++;
- if(*p == '\n' || *p == '\0') {
- /* assign default format if none given! */
- szTemplateName[0] = '\0';
- } else {
- /* we have a template specifier! */
- cflineParseTemplateName(&p, szTemplateName,
- sizeof(szTemplateName) / sizeof(char));
- }
-
- if(szTemplateName[0] == '\0')
- strcpy(szTemplateName, " StdDBFmt");
-
- cflineSetTemplateAndIOV(f, szTemplateName);
-
- /* we now check if the template was present. If not, we
- * can abort this run as the selector line has been
- * disabled. If we don't abort, we'll core dump
- * below. rgerhards 2005-07-29
- */
- if(f->f_type == F_UNUSED)
- break;
-
- dprintf(" template '%s'\n", szTemplateName);
-
- /* If db used, the template have to use the SQL option.
- This is for your own protection (prevent sql injection). */
- if (f->f_pTpl->optFormatForSQL == 0) {
- f->f_type = F_UNUSED;
- logerror("DB logging disabled. You have to use"
- " the SQL or stdSQL option in your template!\n");
- break;
- }
-
- /* If we dedect invalid properties, we disable logging,
- * because right properties are vital at this place.
- * Retries make no sense.
- */
- if (iMySQLPropErr) {
- f->f_type = F_UNUSED;
- dprintf("Trouble with MySQL conncetion properties.\n"
- "MySQL logging disabled.\n");
- } else {
- initMySQL(f);
- }
-#endif /* #ifdef WITH_DB */
+ case '>':
+ parseSelectorActMySQL(&p, f);
break;
case '^': /* bkalkbrenner 2005-09-20: execute shell command */
diff --git a/syslogd.h b/syslogd.h
index 88183633..77e9acad 100644
--- a/syslogd.h
+++ b/syslogd.h
@@ -87,6 +87,7 @@ void untty(void);
void cflineSetTemplateAndIOV(selector_t *f, char *pTemplateName);
void cflineParseTemplateName(uchar** pp, register char* pTemplateName, int iLenTemplate);
void cflineParseFileName(selector_t *f, uchar* p);
+int getSubString(uchar **ppSrc, char *pDst, size_t DstSize, char cSep);
extern int glblHadMemShortage; /* indicates if we had memory shortage some time during the run */
extern syslogCODE rs_prioritynames[];
@@ -114,5 +115,6 @@ extern uid_t dirGID;
extern int bCreateDirs;
extern int iDynaFileCacheSize;
extern char ctty[];
+extern int bModMySQLLoaded;
#endif /* #ifndef SYSLOGD_H_INCLUDED */