From 21122f1bb734aa00fc14564d801ea9dc4804c793 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Thu, 3 Jun 2004 04:32:08 +0000 Subject: moved quoting of fields to DB driver fixed segfault in the mysql escape string function DBi driver working with postgresql. --- CHANGELOG | 5 +++++ Makefile.in | 3 +++ apache13.h | 1 + configure.ac | 10 ++++++++-- docs/manual.xml | 23 ++++++++++++++++++++--- mod_log_sql.c | 48 ++++++++++++++++++++++++------------------------ mod_log_sql.h | 9 ++++++++- mod_log_sql.prj | 15 ++++++++++++++- mod_log_sql_mysql.c | 14 ++++++++------ 9 files changed, 91 insertions(+), 37 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2203a8f..919d2a6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +?: ? +* Added DBI support +* fixed segfault in the mysql driver escape_string function +* switched escape_string driver function to include the string quotes. + 1.98: 2004-04-12 * re-fixed apache.m4 to better detect APR and APU code * fixed for win32 compilation under apache 2 diff --git a/Makefile.in b/Makefile.in index 07278d3..5b4f368 100644 --- a/Makefile.in +++ b/Makefile.in @@ -130,6 +130,9 @@ $(dbiTARGET): $(dbiSOURCES) $(HEADERS) install: $(TARGETS) install-subdirs @@APXS_BIN@ -i $(TARGET); \ @APXS_BIN@ -n $(mysqlNAME) -i $(mysqlTARGET); \ + if test @WANT_DBI_MOD@ -eq 1; then \ + @APXS_BIN@ -n $(dbiNAME) -i $(dbiTARGET); \ + fi; \ if test @WANT_SSL_MOD@ -eq 1; then \ @APXS_BIN@ -n $(sslNAME) -i $(sslTARGET); \ fi; \ diff --git a/apache13.h b/apache13.h index ce4ec64..77bf0ce 100644 --- a/apache13.h +++ b/apache13.h @@ -54,6 +54,7 @@ #define apr_pool_create(a,b) *(a) = ap_make_sub_pool(b) #define apr_pool_destroy ap_destroy_pool +#define apr_pool_cleanup_register ap_register_cleanup #define apr_palloc ap_palloc #define apr_pcalloc ap_pcalloc #define apr_pstrdup ap_pstrdup diff --git a/configure.ac b/configure.ac index 42e2bde..d10ad4f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl Required initializer -AC_INIT(mod_log_sql, 1.98) +AC_INIT(mod_log_sql, 1.99) OOO_CONFIG_NICE(config.nice) AC_PREREQ(2.53) AC_CONFIG_HEADERS(config.h) @@ -35,7 +35,13 @@ WANT_MYSQL_MOD=1 AC_SUBST(WANT_MYSQL_MOD) WANT_PGSQL_MOD=0 AC_SUBST(WANT_PGSQL_MOD) -WANT_DBI_MOD=0 +WANT_DBI_MOD=1 +DBI_LDFLAGS="" +DBI_LIBS="-ldbi" +DBI_CFLAGS="" +AC_SUBST(DBI_LDFLAGS) +AC_SUBST(DBI_LIBS) +AC_SUBST(DBI_CFLAGS) AC_SUBST(WANT_DBI_MOD) case "$target" in diff --git a/docs/manual.xml b/docs/manual.xml index 880bf03..267e9e0 100644 --- a/docs/manual.xml +++ b/docs/manual.xml @@ -706,6 +706,23 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg'; + + LogSQLDisablePreserve + + + LogSQLDisablePreserve + flag + + Example: LogDisablePreserve On + Default: Off + Context; main server config + This option can be enabled to completely disable the preserve file fail back. This may be useful for servers where the file-system is read-only. + If the database is not available those log entries will be lost. + + This is defined only once in the httpd.conf file. + + + LogSQLMachineID @@ -1104,7 +1121,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg'; LogSQLRequestAccept - hostname + substring Example: LogSQLRequestAccept .html .php .jpg Default: if not specified, all requests are 'accepted' @@ -1121,7 +1138,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg'; LogSQLRequestIgnore - hostname + substring Example: LogSQLRequestIgnore root.exe cmd.exe default.ida favicon.ico Context: virtual host @@ -1578,7 +1595,7 @@ ErrorLog /var/log/httpd/server-messages API said: error 2013, Lost connection to MySQL server during query [Tue Nov 12 19:04:10 2002] [error] mod_log_sql: reconnect successful [Tue Nov 12 19:04:10 2002] [error] mod_log_sql: second attempt successful - Reference: MySQL documentation + Reference: MySQL documentation diff --git a/mod_log_sql.c b/mod_log_sql.c index fc9dcc0..dace2d4 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c @@ -504,6 +504,8 @@ static void log_sql_module_init(server_rec *s, apr_pool_t *p) cls->preserve_file = default_p; } } + global_config.db.p = p; + #if defined(WITH_APACHE20) return OK; #endif @@ -908,9 +910,7 @@ static int log_sql_transaction(request_rec *orig) fields = apr_pstrcat(r->pool, fields, (i ? "," : ""), item->sql_field_name, NULL); values = apr_pstrcat(r->pool, values, (i ? "," : ""), - (item->string_contents ? "'" : ""), - global_config.driver->escape(formatted_item, r->pool,&global_config.db), - (item->string_contents ? "'" : ""), NULL); + global_config.driver->escape(formatted_item, r->pool,&global_config.db), NULL); } /* Work through the list of notes defined by LogSQLWhichNotes */ @@ -923,19 +923,19 @@ static int log_sql_transaction(request_rec *orig) if ((theitem = apr_table_get(r->notes, *ptrptr))) { itemsets = apr_pstrcat(r->pool, itemsets, (i > 0 ? "," : ""), - "('", + "(", unique_id, - "','", + ",", global_config.driver->escape(*ptrptr, r->pool,&global_config.db), - "','", + ",", global_config.driver->escape(theitem, r->pool,&global_config.db), - "')", + ")", NULL); i++; } } if ( itemsets != "" ) { - note_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", + note_query = apr_psprintf(r->pool, "insert %s into %s (id, item, val) values %s", /*global_config.insertdelayed?"delayed":*/"", notes_tablename, itemsets); log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: note string: %s", note_query); @@ -951,19 +951,19 @@ static int log_sql_transaction(request_rec *orig) if ((theitem = apr_table_get(r->headers_out, *ptrptr))) { itemsets = apr_pstrcat(r->pool, itemsets, (i > 0 ? "," : ""), - "('", + "(", unique_id, - "','", + ",", global_config.driver->escape(*ptrptr, r->pool,&global_config.db), - "','", + ",", global_config.driver->escape(theitem, r->pool,&global_config.db), - "')", + ")", NULL); i++; } } if ( itemsets != "" ) { - hout_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", + hout_query = apr_psprintf(r->pool, "insert %s into %s (id, item, val) values %s", /*global_config.insertdelayed?"delayed":*/"", hout_tablename, itemsets); log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: header_out string: %s", hout_query); @@ -980,19 +980,19 @@ static int log_sql_transaction(request_rec *orig) if ((theitem = apr_table_get(r->headers_in, *ptrptr))) { itemsets = apr_pstrcat(r->pool, itemsets, (i > 0 ? "," : ""), - "('", + "(", unique_id, - "','", + ",", global_config.driver->escape(*ptrptr, r->pool,&global_config.db), - "','", + ",", global_config.driver->escape(theitem, r->pool,&global_config.db), - "')", + ")", NULL); i++; } } if ( itemsets != "" ) { - hin_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", + hin_query = apr_psprintf(r->pool, "insert %s into %s (id, item, val) values %s", /*global_config.insertdelayed?"delayed":*/"", hin_tablename, itemsets); log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: header_in string: %s", hin_query); @@ -1009,20 +1009,20 @@ static int log_sql_transaction(request_rec *orig) if ( strncmp((theitem = extract_specific_cookie(r, *ptrptr)), "-", 1) ) { itemsets = apr_pstrcat(r->pool, itemsets, (i > 0 ? "," : ""), - "('", + "(", unique_id, - "','", + ",", global_config.driver->escape(*ptrptr, r->pool,&global_config.db), - "','", + ",", global_config.driver->escape(theitem, r->pool,&global_config.db), - "')", + ")", NULL); i++; } } if ( itemsets != "" ) { - cookie_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", + cookie_query = apr_psprintf(r->pool, "insert %s into %s (id, item, val) values %s", /*global_config.insertdelayed?"delayed":*/"", cookie_tablename, itemsets); log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: cookie string: %s", cookie_query); @@ -1030,7 +1030,7 @@ static int log_sql_transaction(request_rec *orig) /* Set up the actual INSERT statement */ - access_query = apr_psprintf(r->pool, "insert %s into `%s` (%s) values (%s)", + access_query = apr_psprintf(r->pool, "insert %s into %s (%s) values (%s)", /*global_config.insertdelayed?"delayed":*/"", transfer_tablename, fields, values); log_error(APLOG_MARK,APLOG_DEBUG,0, r->server,"mod_log_sql: access string: %s", access_query); diff --git a/mod_log_sql.h b/mod_log_sql.h index 56aa2c3..e708f57 100644 --- a/mod_log_sql.h +++ b/mod_log_sql.h @@ -36,6 +36,7 @@ LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p, typedef struct { int connected; /* Are we connected to the DB */ void *handle; /* DB specific connection pointer */ + apr_pool_t *p; /* Pool to allocate handle off of */ apr_table_t *parms; /* DB connection parameters */ } logsql_dbconnection; @@ -79,7 +80,7 @@ typedef enum { typedef struct { /* NULL terminated list of drivers strings */ - char **provided_drivers; + const char **provided_drivers; /* create a connection to the underlying database layer */ logsql_opendb_ret (*connect)(server_rec *s, logsql_dbconnection *db); /* disconnect from the underlying database layer */ @@ -118,6 +119,12 @@ LOGSQL_DECLARE(void) log_sql_register_driver(apr_pool_t *p, static void module_init(server_rec *s, apr_pool_t *p) #endif +#if defined(WITH_APACHE20) +# define LOGSQL_SHUTDOWN \ + static +#endif + + #if defined(WITH_APACHE20) #define LOGSQL_REGISTER_RETURN return OK; #elif defined(WITH_APACHE13) diff --git a/mod_log_sql.prj b/mod_log_sql.prj index bb04bb2..df61439 100644 --- a/mod_log_sql.prj +++ b/mod_log_sql.prj @@ -49,6 +49,18 @@ project.menu.need.terminal=0 project.configure.options= anjuta.program.arguments= +preferences.indent.automatic=1 +preferences.use.tabs=0 +preferences.indent.opening=0 +preferences.indent.closing=0 +preferences.tabsize=4 +preferences.indent.size=4 +preferences.autoformat.style=Style of Kangleipak +preferences.autoformat.custom.style= -i8 -sc -bli0 -bl0 -cbi0 -ss +preferences.autoformat.disable=0 +preferences.debugger.command=gdb +preferences.ui.designer=glade '$(project.name).glade' +preferences.help.browser=devhelp -s '$(current.file.selection)' module.include.name=. module.include.type= @@ -70,7 +82,8 @@ module.source.files=\ mod_log_sql_ssl.c\ mod_log_sql_mysql.c\ contrib/make_combined_log.pl\ - mod_log_sql_pgsql.c + mod_log_sql_pgsql.c\ + mod_log_sql_dbi.c module.pixmap.name=. module.pixmap.type= diff --git a/mod_log_sql_mysql.c b/mod_log_sql_mysql.c index e64044e..f058110 100644 --- a/mod_log_sql_mysql.c +++ b/mod_log_sql_mysql.c @@ -55,7 +55,7 @@ static logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnectio host, tcpport, database, user, socketfile); return LOGSQL_OPENDB_SUCCESS; } else { - log_error(APLOG_MARK,APLOG_DEBUG,0, s,"mod_log_sql: database connection error: %s", + log_error(APLOG_MARK,APLOG_ERR,0, s,"mod_log_sql: database connection error: %s", MYSQL_ERROR(dblink)); log_error(APLOG_MARK,APLOG_DEBUG, 0, s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", host, tcpport, database, user, socketfile); @@ -85,23 +85,24 @@ static const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p, /* Pre-allocate a new string that could hold twice the original, which would only * happen if the whole original string was 'dangerous' characters. */ - to_str = (char *) apr_palloc(p, length * 2 + 1); + to_str = (char *) apr_palloc(p, length * 2 + 3); if (!to_str) { return from_str; } - + strcpy(to_str, "'"); if (!db->connected) { /* Well, I would have liked to use the current database charset. mysql is * unavailable, however, so I fall back to the slightly less respectful * mysql_escape_string() function that uses the default charset. */ - retval = mysql_escape_string(to_str, from_str, length); + retval = mysql_escape_string(to_str+1, from_str, length); } else { /* MySQL is available, so I'll go ahead and respect the current charset when * I perform the escape. */ - retval = mysql_real_escape_string((MYSQL *)db->handle, to_str, from_str, length); + retval = mysql_real_escape_string((MYSQL *)db->handle, to_str+1, from_str, length); } + strcat(to_str,"'"); if (retval) return to_str; @@ -109,6 +110,7 @@ static const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p, return from_str; } } + #if defined(WIN32) #define SIGNAL_GRAB #define SIGNAL_RELEASE @@ -243,7 +245,7 @@ static logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection return LOGSQL_TABLE_SUCCESS; } -static char *supported_drivers[] = {"mysql",NULL}; +static const char *supported_drivers[] = {"mysql",NULL}; static logsql_dbdriver mysql_driver = { supported_drivers, log_sql_mysql_connect, /* open DB connection */ -- cgit