summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--syslogd.c89
-rw-r--r--template.c3
-rw-r--r--test.conf8
4 files changed, 79 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index 02d0394b..f01ff39d 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
@@ -73,8 +73,8 @@ klogd: klogd.o syslog.o pidfile.o ksym.o ksym_mod.o
syslog_tst: syslog_tst.o
${CC} ${LDFLAGS} -o syslog_tst syslog_tst.o
-tsyslogd: syslogd.c version.h
- $(CC) $(CFLAGS) -g -DTESTING $(SYSLOGD_FLAGS) -o tsyslogd syslogd.c $(LIBS)
+tsyslogd: syslogd.c version.h template.o stringbuf.o srUtils.o
+ $(CC) $(CFLAGS) -g -DTESTING $(SYSLOGD_FLAGS) -o tsyslogd syslogd.c pidfile.o template.o stringbuf.o srUtils.o $(LIBS)
tklogd: klogd.c syslog.c ksym.c ksym_mod.c version.h
$(CC) $(CFLAGS) -g -DTESTING $(KLOGD_FLAGS) -o tklogd klogd.c syslog.c ksym.c ksym_mod.c
diff --git a/syslogd.c b/syslogd.c
index 425c14be..925a1b57 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -2972,6 +2972,7 @@ void logmsg(pri, pMsg, flags)
*/
void doSQLEmergencyEscape(register char *p)
{
+printf("In doSQLEmergencyEscape '%s'\n", p);
while(*p) {
if(*p == '\'')
*p = '"';
@@ -2999,6 +3000,7 @@ void doSQLEscape(char **pp, size_t *pLen, unsigned short *pbMustBeFreed)
assert(pLen != NULL);
assert(pbMustBeFreed != NULL);
+printf("In doSQLEscape '%s'\n", *pp);
/* first check if we need to do anything at all... */
for(p = *pp ; *p && *p != '\'' ; ++p)
;
@@ -4220,6 +4222,9 @@ void cfline(line, f)
char buf[MAXLINE];
char szTemplateName[128];
char xbuf[200];
+#ifdef WITH_DB
+ int iMySQLPropErr = 0;
+#endif
dprintf("cfline(%s)\n", line);
@@ -4464,22 +4469,47 @@ void cfline(line, f)
dprintf ("in init() - WITH_DB case \n");
f->f_type = F_MYSQL;
p++;
- dprintf("p is: %s\n", p);
- /* TODO: We have to prove invalide input! */
+ /* Now we read the MySQL connection properties
+ * and verify that the properties are valid.
+ */
if(getSubString(&p, f->f_dbsrv, MAXHOSTNAMELEN+1, ','))
- exit(1);
+ iMySQLPropErr++;
+ if(*f->f_dbsrv == '\0')
+ iMySQLPropErr++;
if(getSubString(&p, f->f_dbname, _DB_MAXDBLEN+1, ','))
- exit(1);
+ iMySQLPropErr++;
+ if(*f->f_dbname == '\0')
+ iMySQLPropErr++;
if(getSubString(&p, f->f_dbuid, _DB_MAXUNAMELEN+1, ','))
- exit(1);
- if(getSubString(&p, f->f_dbpwd, _DB_MAXPWDLEN+1, ','))
- exit(1);
- dprintf("f->f_dbsrv is: %s\n", f->f_dbsrv);
- dprintf("f->f_dbname is: %s\n", f->f_dbname);
- dprintf("f->f_dbuid is: %s\n", f->f_dbuid);
- dprintf("f->f_dbpwd is: %s\n", f->f_dbpwd);
- initMySQL(f);
+ iMySQLPropErr++;
+ if(*f->f_dbuid == '\0')
+ iMySQLPropErr++;
+ if(getSubString(&p, f->f_dbpwd, _DB_MAXPWDLEN+1, ';'))
+ iMySQLPropErr++;
+ if(*p != '\n') {
+ /* 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++;
+ }
+ /* 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"
+ "MySQL logging disabled.\n");
+ }
+ else {
+ initMySQL(f);
+ }
break;
#endif /* #ifdef WITH_DB */
@@ -4658,23 +4688,29 @@ void closeMySQL(register struct filed *f)
*/
void writeMySQL(register struct filed *f)
{
- char sql_command[MAXLINE+1048];
+ char *psz;
+ /* char sql_command[MAXLINE+1048];
char szTimestamp[15];
char szRcvAtTimestamp[15];
formatTimestampToMySQL(&f->f_pMsg->tTIMESTAMP, szTimestamp, sizeof(szTimestamp)/sizeof(char));
formatTimestampToMySQL(&f->f_pMsg->tRcvdAt, szRcvAtTimestamp, sizeof(szTimestamp)/sizeof(char));
+ */
printf("in writeMySQL()\n");
-
- snprintf(sql_command, sizeof(sql_command),
+ iovCreate(f);
+ psz = iovAsString(f);
+printf("psz: \"%s\"\n", psz);
+ printf("in writeMySQL()2\n");
+ /* snprintf(sql_command, sizeof(sql_command),
"INSERT INTO SystemEvents (Message, ReceivedAt, DeviceReportedTime, "
- "Facility, Priority, FromHost, SysLogTag) "
+ "Facility, Priority, FromHost, SysLogTag, InfoUnitID) "
"VALUES "
- " ('%s', '%s', '%s', %d, %d, '%s', '%s')",
+ " ('%s', '%s', '%s', %d, %d, '%s', '%s', 1)",
f->f_pMsg->pszMSG, szRcvAtTimestamp, szTimestamp,
f->f_pMsg->iFacility, f->f_pMsg->iSeverity,
f->f_pMsg->pszHOSTNAME, f->f_pMsg->pszTAG);
+ */
/* query */
- if(mysql_query(&f->f_hmysql, sql_command)) {
+ if(mysql_query(&f->f_hmysql, psz)) {
dprintf("mysql insert failed. ErrNo: %d\n", mysql_errno(&f->f_hmysql));
exit(0);
}
@@ -4690,11 +4726,15 @@ void writeMySQL(register struct filed *f)
* Copy a string byte by byte until the occurrence
* of a given separator.
*
- * \param ppSrc Pointer to a pointer of the source array of characters
- * \param pDst Pointer to the destination array of characters
- * \param DstSize Maximum numbers of characters to store
- * \param cSep Separator char
- * \ret int Returns 0 if no error occured
+ * \param ppSrc Pointer to a pointer of the source array of characters. If a
+ separator detected the Pointer points to the next char after the
+ separator. Except if the end of the string is dedected ('\n').
+ Then it points to the terminator char.
+ * \param pDst Pointer to the destination array of characters. Here the substing
+ will be stored.
+ * \param DstSize Maximum numbers of characters to store.
+ * \param cSep Separator char.
+ * \ret int Returns 0 if no error occured.
*/
int getSubString(char **ppSrc, char *pDst, size_t DstSize, char cSep)
{
@@ -4710,7 +4750,8 @@ int getSubString(char **ppSrc, char *pDst, size_t DstSize, char cSep)
dprintf("in getSubString, error Src buffer > Dst buffer\n");
iErr = 1;
}
- *ppSrc=pSrc+1;
+ if (*pSrc != '\0')
+ *ppSrc=pSrc+1;
*pDst = '\0';
return iErr;
}
diff --git a/template.c b/template.c
index 200f3d01..f4f73da5 100644
--- a/template.c
+++ b/template.c
@@ -22,9 +22,10 @@ static struct template *tplLast = NULL; /* points to the last element of the tem
*/
struct templateEntry* tpeConstruct(struct template *pTpl)
{
+ struct templateEntry *pTpe;
+
assert(pTpl != NULL);
- struct templateEntry *pTpe;
if((pTpe = calloc(1, sizeof(struct templateEntry))) == NULL)
return NULL;
diff --git a/test.conf b/test.conf
index c7a994db..25827ba8 100644
--- a/test.conf
+++ b/test.conf
@@ -16,7 +16,7 @@
# \ = \\
# --> '\' is used to escape (as in C)
#$template TraditionalFormat,"%UxTradMsg%\n",1024
-#$template MySQLInsert,"insert iut, msg values (1, '%msg') into systemevents",SQL,MAXSIZE=1024
+#$template MySQLInsert,"insert iut, msg values (1, '%msg%') into systemevents",SQL,MAXSIZE=1024
$template TraditionalFormat,"%timegenerated% %HOSTNAME% %syslogtag%%msg%\n"
$template precise,"%syslogpriority%,%syslogfacility%,%timegenerated%,%HOSTNAME%,%syslogtag%,%msg%\n",1024
$template RFC3164fmt,"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%"
@@ -37,5 +37,11 @@ $template wallmsg,"\r\n\7Message from syslogd@%HOSTNAME% at %timegenerated:::dat
#*.* *;MySQLInsert
#*.* /home/rger/proj/rsyslog/logfile;precise
#*.* /home/rger/proj/rsyslog/logfile;UserMsg
+<<<<<<< test.conf
#*.* /home/rger/proj/rsyslog/tradfile;TraditionalFormat
#*.* @172.19.2.16;RFC3164fmt
+*.* >localhost,AdisconDB,root,
+=======
+#*.* /home/rger/proj/rsyslog/tradfile;TraditionalFormat
+#*.* @172.19.2.16;RFC3164fmt
+>>>>>>> 1.4