summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlaforge <laforge>2001-05-17 15:06:57 +0000
committerlaforge <laforge>2001-05-17 15:06:57 +0000
commita426f4220459a4c228a1ae4f286a873309c29a18 (patch)
tree8f94406dcc5294a7b9948661e8745a4e4a1862c5
parent85d9f8bfc13384d3f6326be439eb3374cdc5bec1 (diff)
Support for old MySQL databases (Alexander Janssen)
-rw-r--r--Rules.make.in2
-rw-r--r--configure.in20
-rw-r--r--mysql/ulogd_MYSQL.c14
3 files changed, 32 insertions, 4 deletions
diff --git a/Rules.make.in b/Rules.make.in
index 432df20..2fc77ea 100644
--- a/Rules.make.in
+++ b/Rules.make.in
@@ -29,6 +29,6 @@ ULOGD_SL:=BASE OPRINT PWSNIFF LOGEMU
# mysql output support
#ULOGD_SL+=MYSQL
-MYSQL_CFLAGS=-I@MYSQLINCLUDES@
+MYSQL_CFLAGS=-I@MYSQLINCLUDES@ -D@EXTRA_MYSQL_DEF@
MYSQL_LDFLAGS=@DATABASE_LIB_DIR@ @DATABASE_LIB@
diff --git a/configure.in b/configure.in
index da22cd8..ca693e8 100644
--- a/configure.in
+++ b/configure.in
@@ -86,6 +86,25 @@ else
else
MYSQLEXTRALIBS=
fi
+
+ dnl Here we check whether we have an old MySQL client library
+ dnl installed, which does not support the mysql_real_escape_string(),
+ dnl but the real_escape_string() function.
+ dnl Having a look in the libary itself should be more reliable than
+ dnl parsing the output of mysql --version.
+
+ AC_MSG_CHECKING(for mysql_real_escape_string support)
+
+ MYSQL_FUNCTION_TEST=`strings ${MYSQLLIBS}/libmysqlclient.a | grep mysql_real_escape_string`
+
+ if test "x$MYSQL_FUNCTION_TEST" = x
+ then
+ EXTRA_MYSQL_DEF="OLD_MYSQL=1 "
+ AC_MSG_RESULT(found an older version of MySQL)
+ else
+ AC_MSG_RESULT(found a newer version of MySQL)
+ fi
+
fi
])
@@ -93,6 +112,7 @@ AC_SUBST(DATABASE_DIR)
AC_SUBST(DATABASE_LIB)
AC_SUBST(DATABASE_LIB_DIR)
AC_SUBST(DB_DEF)
+AC_SUBST(EXTRA_MYSQL_DEF)
AC_SUBST(DATABASE_DRIVERS)
diff --git a/mysql/ulogd_MYSQL.c b/mysql/ulogd_MYSQL.c
index b8ff95e..1dcd3c4 100644
--- a/mysql/ulogd_MYSQL.c
+++ b/mysql/ulogd_MYSQL.c
@@ -1,13 +1,16 @@
-/* ulogd_MYSQL.c, Version $Revision: 1.1 $
+/* ulogd_MYSQL.c, Version $Revision: 1.2 $
*
* ulogd output plugin for logging to a MySQL database
*
* (C) 2000 by Harald Welte <laforge@gnumonks.org>
* This software is distributed under the terms of GNU GPL
*
- * $Id: ulogd_MYSQL.c,v 1.1 2000/11/20 19:37:55 laforge Exp $
+ * $Id: ulogd_MYSQL.c,v 1.2 2001/02/16 18:07:52 laforge Exp $
*
- **/
+ * 15.5.2001, Alex Janssen <alex@ynfonatic.de>:
+ * Added a compability option for older MySQL-servers, which
+ * don't support mysql_real_escape_string
+ */
#include <stdlib.h>
#include <string.h>
@@ -130,8 +133,13 @@ static int _mysql_output(ulog_iret_t *result)
break;
case ULOGD_RET_STRING:
*stmt_ins++ = '\'';
+#ifdef OLD_MYSQL
+ mysql_escape_string(stmt_ins, res->value.ptr,
+ strlen(res->value.ptr));
+#else
mysql_real_escape_string(dbh, stmt_ins,
res->value.ptr, strlen(res->value.ptr));
+#endif
stmt_ins = stmt + strlen(stmt);
sprintf(stmt_ins, "',");
/* sprintf(stmt_ins, "'%s',", res->value.ptr); */