]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
add support for string- and inet- logging of ipadresses to postgresql
authorlaforge <laforge>
Wed, 28 Aug 2002 09:41:17 +0000 (09:41 +0000)
committerYasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>
Wed, 21 May 2008 18:56:48 +0000 (03:56 +0900)
(Martin Kähmer)

Rules.make.in
configure.in
extensions/ulogd_BASE.c
pgsql/ulogd_PGSQL.c

index 428b81fbce5b342a1f3ede1070b9d402f3bf02d9..e5339f3e249e8939e63a27012752b690403572c9 100644 (file)
@@ -36,5 +36,5 @@ MYSQL_LDFLAGS=@DATABASE_LIB_DIR@ @DATABASE_LIB@
 
 # postgreSQL output support
 #ULOGD_SL+=PGSQL
-PGSQL_CFLAGS=-I@PGSQLINCLUDES@
+PGSQL_CFLAGS=-I@PGSQLINCLUDES@ @EXTRA_PGSQL_DEF@
 PGSQL_LDFLAGS=@DATABASE_LIB_DIR@ @DATABASE_LIB@
index 4a749ebc625be53b486ea3a6dc28c38714da9f0f..bf4645f389949e4e05ac186e624b97c5b71ab8f1 100644 (file)
@@ -175,11 +175,26 @@ else
 fi      
 ])      
 
+dnl
+dnl Check whether the user wants to log IP-addresses as strings rather
+dnl than integers to his pgsql-database.
+dnl
+
+AC_ARG_WITH(pgsql-log-ip-as-string,
+ --with-pgsql-log-ip-as-string         log IPs as string rather than as interger
+,[
+   EXTRA_PGSQL_DEF="-DIP_AS_STRING=1"
+])
+
+
+
+
 AC_SUBST(DATABASE_DIR)
 AC_SUBST(DATABASE_LIB)
 AC_SUBST(DATABASE_LIB_DIR)
 AC_SUBST(DB_DEF)
 AC_SUBST(EXTRA_MYSQL_DEF)
+AC_SUBST(EXTRA_PGSQL_DEF)
 
 AC_SUBST(DATABASE_DRIVERS)
 AC_SUBST(HAVE_PCAP_H)
index b383f8c1ab1c9ce4a6aebf662f84d599ca2e5daa..180370b8e76ea27b145af9a54e314ec1b022a079 100644 (file)
@@ -1,4 +1,4 @@
-/* ulogd_MAC.c, Version $Revision: 1.12 $
+/* ulogd_MAC.c, Version $Revision: 1.13 $
  *
  * ulogd interpreter plugin for 
  *     o MAC addresses
@@ -26,7 +26,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  
- * $Id: ulogd_BASE.c,v 1.12 2002/06/13 12:55:21 laforge Exp $
+ * $Id: ulogd_BASE.c,v 1.13 2002/08/25 15:43:51 laforge Exp $
  *
  */
 
@@ -232,32 +232,23 @@ static ulog_iret_t *_interp_tcphdr(struct ulog_interpreter *ip,
        ret[3].flags |= ULOGD_RETF_VALID;
        ret[4].value.ui16 = ntohs(tcph->window);
        ret[4].flags |= ULOGD_RETF_VALID;
+
+       ret[5].value.b = tcph->urg;
+       ret[5].flags |= ULOGD_RETF_VALID;
        if (tcph->urg) {
-               ret[5].value.b = tcph->urg;
-               ret[5].flags |= ULOGD_RETF_VALID;
                ret[6].value.ui16 = ntohs(tcph->urg_ptr);
                ret[6].flags |= ULOGD_RETF_VALID;
        }
-       if (tcph->ack) {
-               ret[7].value.b = tcph->ack;
-               ret[7].flags |= ULOGD_RETF_VALID;
-       }
-       if (tcph->psh) {
-               ret[8].value.b = tcph->psh;
-               ret[8].flags |= ULOGD_RETF_VALID;
-       }
-       if (tcph->rst) {
-               ret[9].value.b = tcph->rst;
-               ret[9].flags |= ULOGD_RETF_VALID;
-       }
-       if (tcph->syn) {
-               ret[10].value.b = tcph->syn;
-               ret[10].flags |= ULOGD_RETF_VALID;
-       }
-       if (tcph->fin) {
-               ret[11].value.b = tcph->fin;
-               ret[11].flags |= ULOGD_RETF_VALID;
-       }
+       ret[7].value.b = tcph->ack;
+       ret[7].flags |= ULOGD_RETF_VALID;
+       ret[8].value.b = tcph->psh;
+       ret[8].flags |= ULOGD_RETF_VALID;
+       ret[9].value.b = tcph->rst;
+       ret[9].flags |= ULOGD_RETF_VALID;
+       ret[10].value.b = tcph->syn;
+       ret[10].flags |= ULOGD_RETF_VALID;
+       ret[11].value.b = tcph->fin;
+       ret[11].flags |= ULOGD_RETF_VALID;
        
        return ret;
 }
index a54a5ed3394a91cc475a43ce6d3d3c50ed565052..01c7b92182c3155e7ac8d1d1f8dcaea1bfe1bdd6 100644 (file)
@@ -17,7 +17,8 @@
 #include "ulogd.h"
 #include "conffile.h"
 
-#ifdef DEBUG_PQSQL
+
+#ifdef DEBUG_PGSQL
 #define DEBUGP(x, args...)     fprintf(stderr, x, ## args)
 #else
 #define DEBUGP(x, args...)
@@ -123,21 +124,13 @@ static int _pgsql_output(ulog_iret_t *result)
                                sprintf(stmt_ins, "%u,", res->value.ui16);
                                break;
                        case ULOGD_RET_IPADDR:
-/* #ifdef IP_AS_STRING
+#ifdef IP_AS_STRING
                                *stmt_ins++ = '\'';
-                               tmpstr = inet_ntoa(ntohl(res->value.ui32));
-#ifdef OLD_PGSQL
-                               pgsql_escape_string(stmt_ins, tmpstr,
-                                                   strlen(tmpstr));
-#else
-                               pgsql_real_escape_string(dbh, stmt_ins,
-                                                        tmpstr,
-                                                        strlen(tmpstr));
-#endif /* OLD_PGSQL */
-/*
-                                stmt_ins = stmt + strlen(stmt);
-                                sprintf(stmt_ins, "',");
-                                break;
+                               tmpstr = (char *)inet_ntoa(ntohl(res->value.ui32));
+                               PQescapeString(stmt_ins,tmpstr,strlen(tmpstr)); 
+                               stmt_ins = stmt + strlen(stmt);
+                               sprintf(stmt_ins, "',");
+                               break;
 #endif /* IP_AS_STRING */
                                /* EVIL: fallthrough when logging IP as
                                 * u_int32_t */
@@ -149,25 +142,17 @@ static int _pgsql_output(ulog_iret_t *result)
                                sprintf(stmt_ins, "%lu,", res->value.ui64);
                                break;
                        case ULOGD_RET_BOOL:
-                               sprintf(stmt_ins, "1,");
+                               sprintf(stmt_ins, "'%d',", res->value.b);
                                break;
                        case ULOGD_RET_STRING:
                                *stmt_ins++ = '\'';
-/*  Change by Jaki
-#ifdef OLD_PGSQL
-                               pgsql_escape_string(stmt_ins, res->value.ptr,
-                                       strlen(res->value.ptr));
-#else
-                               pgsql_real_escape_string(dbh, stmt_ins,
-                                       res->value.ptr, strlen(res->value.ptr));
-#endif
-*End Change by Jaki
-*/
-                                strcpy(stmt_ins,"\'");
-                               strcpy(stmt_ins,res->value.ptr);  /* Added by Jaki */
+                               PQescapeString(stmt_ins,res->value.ptr,strlen(res->value.ptr)); 
                                stmt_ins = stmt + strlen(stmt);
                                sprintf(stmt_ins, "',");
-                       /* sprintf(stmt_ins, "'%s',", res->value.ptr); */
+                               break;
+                       case ULOGD_RET_RAW:
+                               ulogd_log(ULOGD_NOTICE,"%s: pgsql doesn't support type RAW\n",res->key);
+                               sprintf(stmt_ins, "NULL,");
                                break;
                        default:
                                ulogd_log(ULOGD_NOTICE,