summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--syslogd.c36
2 files changed, 29 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index abb36daf..4ccbf27f 100644
--- a/Makefile
+++ b/Makefile
@@ -3,8 +3,8 @@
CC= gcc
#CFLAGS= -g -DSYSV -Wall
LDFLAGS= -g
-CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce
-#CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce -DWITH_DB
+#CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce
+CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce -DWITH_DB
LDFLAGS= -s
# Look where your install program is.
@@ -13,7 +13,7 @@ BINDIR = /usr/sbin
MANDIR = /usr/man
# Uncommenting the following to use mysql.
-#LIBS = -lmysqlclient #/var/lib/mysql/mysql
+LIBS = -lmysqlclient #/var/lib/mysql/mysql
# There is one report that under an all ELF system there may be a need to
# explicilty link with libresolv.a. If linking syslogd fails you may wish
diff --git a/syslogd.c b/syslogd.c
index f6f41888..58584e68 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -974,6 +974,7 @@ static char template_TraditionalFormat[] = "\"%timegenerated% %HOSTNAME% %syslog
static char template_WallFmt[] = "\"\r\n\7Message from syslogd@%HOSTNAME% at %timegenerated% ...\r\n %syslogtag%%msg%\n\r\"";
static char template_StdFwdFmt[] = "\"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%\"";
static char template_StdUsrMsgFmt[] = "\" %syslogtag%%msg%\n\r\"";
+static char template_StdDBFmt[] = "\"insert into SystemEvents (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')\",SQL";
/* end template */
/* Function prototypes. */
@@ -2200,6 +2201,8 @@ int main(argc, argv)
tplAddLine(" StdFwdFmt", &pTmp);
pTmp = template_StdUsrMsgFmt;
tplAddLine(" StdUsrMsgFmt", &pTmp);
+ pTmp = template_StdDBFmt;
+ tplAddLine(" StdDBFmt", &pTmp);
/* prepare emergency logging system */
@@ -3835,13 +3838,14 @@ void die(sig)
errno = 0;
logmsgInternal(LOG_SYSLOG|LOG_INFO, buf, LocalHostName, ADDDATE);
}
-
+#ifdef WITH_DB
/* Close the MySQL connection */
for (lognum = 0; lognum <= nlogs; lognum++) {
f = &Files[lognum];
if (f->f_type == F_MYSQL)
closeMySQL(f);
}
+#endif
/* now clean up the listener part */
@@ -4641,26 +4645,38 @@ void cfline(line, f)
/* we have a template specifier! */
cflineParseTemplateName(f, &p, szTemplateName,
sizeof(szTemplateName) / sizeof(char));
- cflineSetTemplateAndIOV(f, szTemplateName);
- dprintf(" template '%s'", szTemplateName);
}
- else {
- printf("No template assigned!\n");
- iMySQLPropErr++;
+ else /* assign default format if none given! */
+ szTemplateName[0] = '\0';
+
+ if(szTemplateName[0] == '\0')
+ strcpy(szTemplateName, " StdDBFmt");
+
+ cflineSetTemplateAndIOV(f, szTemplateName);
+ 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 != 1)
+ {
+ f->f_type = F_UNUSED;
+ dprintf("DB logging disabled. You have to use"
+ " the SQL option in your template!\n");
+
}
+
/* If we dedect invalid properties, we disable logging,
* because right properties are vital at this place.
* Retrials make no sens.
*/
if (iMySQLPropErr) {
f->f_type = F_UNUSED;
- printf("Trouble with MySQL conncetion properties.\n"
+ dprintf("Trouble with MySQL conncetion properties.\n"
"MySQL logging disabled.\n");
}
else {
initMySQL(f);
}
- /* TODO: add handling for standard template! rgerhards */
break;
#endif /* #ifdef WITH_DB */
@@ -4877,7 +4893,7 @@ void writeMySQL(register struct filed *f)
char *psz;
int iCounter=0;
assert(f != NULL);
- dprintf("in writeMySQL()\n");
+ /* dprintf("in writeMySQL()\n"); */
iovCreate(f);
psz = iovAsString(f);
@@ -4959,7 +4975,7 @@ void DBErrorHandler(register struct filed *f)
int checkDBErrorState(register struct filed *f)
{
assert(f != NULL);
- dprintf("in checkDBErrorState, timeResumeOnError: %d\n", f->f_timeResumeOnError);
+ /* dprintf("in checkDBErrorState, timeResumeOnError: %d\n", f->f_timeResumeOnError); */
/* If timeResumeOnError == 0 no error occured,
we can return with 0 (no error) */