summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Edward Rudd 2006-11-07 02:31:26 +0000
committerGravatar Edward Rudd 2006-11-07 02:31:26 +0000
commit45d25f947b7cf068530f009e8846cd3ccde51220 (patch)
tree83b62f09aa00e5e9cee1ec47859bdcd66d29732e
parent22d1542ac15c4e93cabe834e2536cdba296d30d6 (diff)
don't segfault if driver module isn't loaded
-rw-r--r--mod_log_sql.c72
1 files changed, 42 insertions, 30 deletions
diff --git a/mod_log_sql.c b/mod_log_sql.c
index d92df49..1892eec 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -9,7 +9,7 @@
9#endif 9#endif
10 10
11#ifdef HAVE_CONFIG_H 11#ifdef HAVE_CONFIG_H
12/* Undefine these to prevent conflicts between Apache ap_config_auto.h and 12/* Undefine these to prevent conflicts between Apache ap_config_auto.h and
13 * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt. 13 * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt.
14 */ 14 */
15#undef PACKAGE_BUGREPORT 15#undef PACKAGE_BUGREPORT
@@ -153,6 +153,9 @@ LOGSQL_DECLARE(void) log_sql_register_driver(apr_pool_t *p,
153static logsql_opendb_ret log_sql_opendb_link(server_rec* s) 153static logsql_opendb_ret log_sql_opendb_link(server_rec* s)
154{ 154{
155 logsql_opendb_ret result; 155 logsql_opendb_ret result;
156 if (global_config.driver == NULL) {
157 return LOGSQL_OPENDB_FAIL;
158 }
156 if (global_config.forcepreserve) { 159 if (global_config.forcepreserve) {
157 //global_config.db.connected = 1; 160 //global_config.db.connected = 1;
158 return LOGSQL_OPENDB_PRESERVE; 161 return LOGSQL_OPENDB_PRESERVE;
@@ -170,7 +173,7 @@ static logsql_opendb_ret log_sql_opendb_link(server_rec* s)
170 if (result==LOGSQL_OPENDB_FAIL) { 173 if (result==LOGSQL_OPENDB_FAIL) {
171 global_config.db.connected = 0; 174 global_config.db.connected = 0;
172 } else { 175 } else {
173 global_config.db.connected = 1; 176 global_config.db.connected = 1;
174 } 177 }
175 return result; 178 return result;
176 } else { 179 } else {
@@ -182,7 +185,7 @@ static logsql_opendb_ret log_sql_opendb_link(server_rec* s)
182 185
183static void preserve_entry(request_rec *r, const char *query) 186static void preserve_entry(request_rec *r, const char *query)
184{ 187{
185 logsql_state *cls = ap_get_module_config(r->server->module_config, 188 logsql_state *cls = ap_get_module_config(r->server->module_config,
186 &log_sql_module); 189 &log_sql_module);
187 #if defined(WITH_APACHE20) 190 #if defined(WITH_APACHE20)
188 apr_file_t *fp; 191 apr_file_t *fp;
@@ -223,8 +226,8 @@ static void preserve_entry(request_rec *r, const char *query)
223 * ------------------------------------------------*/ 226 * ------------------------------------------------*/
224 227
225 228
226static const char *set_global_flag_slot(cmd_parms *cmd, 229static const char *set_global_flag_slot(cmd_parms *cmd,
227 void *struct_ptr, 230 void *struct_ptr,
228 int flag) 231 int flag)
229{ 232{
230 void *ptr = &global_config; 233 void *ptr = &global_config;
@@ -268,7 +271,7 @@ static const char *set_server_string_slot(cmd_parms *cmd,
268 int offset = (int)(long)cmd->info; 271 int offset = (int)(long)cmd->info;
269 272
270 *(const char **)((char *)ptr + offset) = arg; 273 *(const char **)((char *)ptr + offset) = arg;
271 274
272 return NULL; 275 return NULL;
273} 276}
274 277
@@ -282,14 +285,14 @@ static const char *set_server_file_slot(cmd_parms *cmd,
282 const char *path; 285 const char *path;
283 286
284 path = ap_server_root_relative(cmd->pool, (char *)arg); 287 path = ap_server_root_relative(cmd->pool, (char *)arg);
285 288
286 if (!path) { 289 if (!path) {
287 return apr_pstrcat(cmd->pool, "Invalid file path ", 290 return apr_pstrcat(cmd->pool, "Invalid file path ",
288 arg, NULL); 291 arg, NULL);
289 } 292 }
290 293
291 *(const char **)((char*)ptr + offset) = path; 294 *(const char **)((char*)ptr + offset) = path;
292 295
293 return NULL; 296 return NULL;
294} 297}
295 298
@@ -299,7 +302,7 @@ static const char *set_logformat_slot(cmd_parms *cmd,
299{ 302{
300 logsql_state *cfg = ap_get_module_config(cmd->server->module_config, 303 logsql_state *cfg = ap_get_module_config(cmd->server->module_config,
301 &log_sql_module); 304 &log_sql_module);
302 305
303 cfg->transfer_log_format = arg; 306 cfg->transfer_log_format = arg;
304/* apr_pool_clear(cfg->parsed_pool);*/ 307/* apr_pool_clear(cfg->parsed_pool);*/
305 cfg->parsed_log_format = apr_pcalloc(cfg->parsed_pool, 308 cfg->parsed_log_format = apr_pcalloc(cfg->parsed_pool,
@@ -342,7 +345,7 @@ static const char *set_dbparam_slot(cmd_parms *cmd,
342} 345}
343 346
344/* Sets basic connection info */ 347/* Sets basic connection info */
345static const char *set_log_sql_info(cmd_parms *cmd, void *dummy, 348static const char *set_log_sql_info(cmd_parms *cmd, void *dummy,
346 const char *host, const char *user, const char *pwd) 349 const char *host, const char *user, const char *pwd)
347{ 350{
348 if (!user) { /* user is null, so only one arg passed */ 351 if (!user) { /* user is null, so only one arg passed */
@@ -370,7 +373,7 @@ static const char *set_log_sql_info(cmd_parms *cmd, void *dummy,
370 if (off) 373 if (off)
371 *off='\0'; 374 *off='\0';
372 set_dbparam(cmd, NULL, "database", uri.path); 375 set_dbparam(cmd, NULL, "database", uri.path);
373 376
374 } 377 }
375 } else { 378 } else {
376 if (*host != '.') { 379 if (*host != '.') {
@@ -397,7 +400,7 @@ static const char *add_server_string_slot(cmd_parms *cmd,
397 apr_array_header_t *ary = *(apr_array_header_t **)((char *)ptr + offset); 400 apr_array_header_t *ary = *(apr_array_header_t **)((char *)ptr + offset);
398 addme = apr_array_push(ary); 401 addme = apr_array_push(ary);
399 *addme = apr_pstrdup(ary->pool, arg); 402 *addme = apr_pstrdup(ary->pool, arg);
400 403
401 return NULL; 404 return NULL;
402} 405}
403 406
@@ -409,13 +412,15 @@ static const char *add_server_string_slot(cmd_parms *cmd,
409#if defined(WITH_APACHE20) 412#if defined(WITH_APACHE20)
410static apr_status_t log_sql_close_link(void *data) 413static apr_status_t log_sql_close_link(void *data)
411{ 414{
412 global_config.driver->disconnect(&global_config.db); 415 if (global_config.driver)
416 global_config.driver->disconnect(&global_config.db);
413 return APR_SUCCESS; 417 return APR_SUCCESS;
414} 418}
415#elif defined(WITH_APACHE13) 419#elif defined(WITH_APACHE13)
416static void log_sql_child_exit(server_rec *s, apr_pool_t *p) 420static void log_sql_child_exit(server_rec *s, apr_pool_t *p)
417{ 421{
418 global_config.driver->disconnect(&global_config.db); 422 if (global_config.driver)
423 global_config.driver->disconnect(&global_config.db);
419} 424}
420#endif 425#endif
421 426
@@ -435,8 +440,13 @@ static void log_sql_child_init(server_rec *s, apr_pool_t *p)
435 retval = log_sql_opendb_link(s); 440 retval = log_sql_opendb_link(s);
436 switch (retval) { 441 switch (retval) {
437 case LOGSQL_OPENDB_FAIL: 442 case LOGSQL_OPENDB_FAIL:
438 log_error(APLOG_MARK, APLOG_ERR, 0, s, 443 if (global_config.driver==NULL) {
439 "mod_log_sql: child spawned but unable to open database link"); 444 log_error(APLOG_MARK, APLOG_ERR, 0, s,
445 "mod_log_sql: Driver module not loaded");
446 } else {
447 log_error(APLOG_MARK, APLOG_ERR, 0, s,
448 "mod_log_sql: child spawned but unable to open database link");
449 }
440 break; 450 break;
441 case LOGSQL_OPENDB_SUCCESS: 451 case LOGSQL_OPENDB_SUCCESS:
442 case LOGSQL_OPENDB_ALREADY: 452 case LOGSQL_OPENDB_ALREADY:
@@ -505,8 +515,8 @@ static void log_sql_module_init(server_rec *s, apr_pool_t *p)
505#endif 515#endif
506} 516}
507 517
508/* This function handles calling the DB module, handling errors 518/* This function handles calling the DB module, handling errors
509 * of missing tables and lost DB connections, and falling back to 519 * of missing tables and lost DB connections, and falling back to
510 * preserving the DB query. 520 * preserving the DB query.
511 * 521 *
512 * Parms: request record, table type, table name, and the full SQL command 522 * Parms: request record, table type, table name, and the full SQL command
@@ -519,7 +529,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
519 logsql_state *cls = ap_get_module_config(r->server->module_config, 529 logsql_state *cls = ap_get_module_config(r->server->module_config,
520 &log_sql_module); 530 &log_sql_module);
521 531
522 if (!global_config.db.connected) { 532 if (!global_config.db.connected || global_config.driver == NULL) {
523 /* preserve query */ 533 /* preserve query */
524 return LOGSQL_QUERY_NOLINK; 534 return LOGSQL_QUERY_NOLINK;
525 } 535 }
@@ -580,7 +590,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
580 if (global_config.createtables) { 590 if (global_config.createtables) {
581 log_error(APLOG_MARK,APLOG_ERR,0,r->server, 591 log_error(APLOG_MARK,APLOG_ERR,0,r->server,
582 "table doesn't exist...creating now"); 592 "table doesn't exist...creating now");
583 if ((result = global_config.driver->create_table(r, &global_config.db, table_type, 593 if ((result = global_config.driver->create_table(r, &global_config.db, table_type,
584 table_name))!=LOGSQL_TABLE_SUCCESS) { 594 table_name))!=LOGSQL_TABLE_SUCCESS) {
585 log_error(APLOG_MARK,APLOG_ERR,result,r->server, 595 log_error(APLOG_MARK,APLOG_ERR,result,r->server,
586 "child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r)); 596 "child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r));
@@ -736,7 +746,7 @@ static void *log_sql_merge_state(apr_pool_t *p, void *basev, void *addv)
736 /* server_root_relative the preserve file location */ 746 /* server_root_relative the preserve file location */
737 if (child->preserve_file == DEFAULT_PRESERVE_FILE) 747 if (child->preserve_file == DEFAULT_PRESERVE_FILE)
738 child->preserve_file = ap_server_root_relative(p, DEFAULT_PRESERVE_FILE); 748 child->preserve_file = ap_server_root_relative(p, DEFAULT_PRESERVE_FILE);
739 749
740 if (child->notes_table_name == DEFAULT_NOTES_TABLE_NAME) 750 if (child->notes_table_name == DEFAULT_NOTES_TABLE_NAME)
741 child->notes_table_name = parent->notes_table_name; 751 child->notes_table_name = parent->notes_table_name;
742 752
@@ -780,7 +790,9 @@ static int log_sql_transaction(request_rec *orig)
780 const char *hout_tablename = cls->hout_table_name; 790 const char *hout_tablename = cls->hout_table_name;
781 const char *hin_tablename = cls->hin_table_name; 791 const char *hin_tablename = cls->hin_table_name;
782 const char *cookie_tablename = cls->cookie_table_name; 792 const char *cookie_tablename = cls->cookie_table_name;
783 793 if (global_config.driver == NULL) {
794 return OK;
795 }
784 /* We handle mass virtual hosting differently. Dynamically determine the name 796 /* We handle mass virtual hosting differently. Dynamically determine the name
785 * of the table from the virtual server's name, and flag it for creation. 797 * of the table from the virtual server's name, and flag it for creation.
786 */ 798 */
@@ -803,7 +815,7 @@ static int log_sql_transaction(request_rec *orig)
803 if (*p == '-') *p = '_'; 815 if (*p == '-') *p = '_';
804 ++p; 816 ++p;
805 } 817 }
806 818
807 /* Find memory long enough to hold the table name + \0. */ 819 /* Find memory long enough to hold the table name + \0. */
808 transfer_tablename = apr_pstrcat(orig->pool, access_base, servername, NULL); 820 transfer_tablename = apr_pstrcat(orig->pool, access_base, servername, NULL);
809 notes_tablename = apr_pstrcat(orig->pool, notes_base, servername, NULL); 821 notes_tablename = apr_pstrcat(orig->pool, notes_base, servername, NULL);
@@ -814,7 +826,7 @@ static int log_sql_transaction(request_rec *orig)
814 /* Tell this virtual server its transfer table name, and 826 /* Tell this virtual server its transfer table name, and
815 * turn on create_tables, which is implied by massvirtual. 827 * turn on create_tables, which is implied by massvirtual.
816 */ 828 */
817 829
818 global_config.createtables = 1; 830 global_config.createtables = 1;
819 } 831 }
820 832
@@ -1130,7 +1142,7 @@ static const command_rec log_sql_cmds[] = {
1130 (void *)APR_OFFSETOF(logsql_state,preserve_file), RSRC_CONF, 1142 (void *)APR_OFFSETOF(logsql_state,preserve_file), RSRC_CONF,
1131 "Name of the file to use for data preservation during database downtime") 1143 "Name of the file to use for data preservation during database downtime")
1132 , 1144 ,
1133 AP_INIT_FLAG("LogSQLCreateTables", set_global_nmv_flag_slot, 1145 AP_INIT_FLAG("LogSQLCreateTables", set_global_nmv_flag_slot,
1134 (void *)APR_OFFSETOF(global_config_t, createtables), RSRC_CONF, 1146 (void *)APR_OFFSETOF(global_config_t, createtables), RSRC_CONF,
1135 "Turn on module's capability to create its SQL tables on the fly") 1147 "Turn on module's capability to create its SQL tables on the fly")
1136 , 1148 ,
@@ -1140,7 +1152,7 @@ static const command_rec log_sql_cmds[] = {
1140 "Activates option(s) useful for ISPs performing mass virutal hosting") 1152 "Activates option(s) useful for ISPs performing mass virutal hosting")
1141 , 1153 ,
1142 AP_INIT_TAKE1("LogSQLTransferLogTable", set_server_nmv_string_slot, 1154 AP_INIT_TAKE1("LogSQLTransferLogTable", set_server_nmv_string_slot,
1143 (void *)APR_OFFSETOF(logsql_state, transfer_table_name), RSRC_CONF, 1155 (void *)APR_OFFSETOF(logsql_state, transfer_table_name), RSRC_CONF,
1144 "The database table that holds the transfer log") 1156 "The database table that holds the transfer log")
1145 , 1157 ,
1146 AP_INIT_TAKE1("LogSQLNotesLogTable", set_server_nmv_string_slot, 1158 AP_INIT_TAKE1("LogSQLNotesLogTable", set_server_nmv_string_slot,
@@ -1183,7 +1195,7 @@ static const command_rec log_sql_cmds[] = {
1183 "List of remote hosts to ignore. Accesses that match will not be logged to database") 1195 "List of remote hosts to ignore. Accesses that match will not be logged to database")
1184 , 1196 ,
1185 /* Special loggin table configuration */ 1197 /* Special loggin table configuration */
1186 AP_INIT_TAKE1("LogSQLWhichCookie", set_server_string_slot, 1198 AP_INIT_TAKE1("LogSQLWhichCookie", set_server_string_slot,
1187 (void *)APR_OFFSETOF(logsql_state, cookie_name), RSRC_CONF, 1199 (void *)APR_OFFSETOF(logsql_state, cookie_name), RSRC_CONF,
1188 "The single cookie that you want logged in the access_log when using the 'c' config directive") 1200 "The single cookie that you want logged in the access_log when using the 'c' config directive")
1189 , 1201 ,
@@ -1207,7 +1219,7 @@ static const command_rec log_sql_cmds[] = {
1207 "<br><b>Deprecated</b><br>The following Commands are deprecated and should not be used.. <br>Read the documentation for more information<br><b>Deprecated</b>") 1219 "<br><b>Deprecated</b><br>The following Commands are deprecated and should not be used.. <br>Read the documentation for more information<br><b>Deprecated</b>")
1208 , 1220 ,
1209 /* Deprecated commands */ 1221 /* Deprecated commands */
1210 AP_INIT_TAKE1("LogSQLDatabase", set_dbparam_slot, 1222 AP_INIT_TAKE1("LogSQLDatabase", set_dbparam_slot,
1211 (void *)"database", RSRC_CONF, 1223 (void *)"database", RSRC_CONF,
1212 "<b>(Deprecated) Use LogSQLDBParam database dbname.</b> The name of the database database for logging") 1224 "<b>(Deprecated) Use LogSQLDBParam database dbname.</b> The name of the database database for logging")
1213 , 1225 ,
@@ -1219,7 +1231,7 @@ static const command_rec log_sql_cmds[] = {
1219 (void *)"socketfile", RSRC_CONF, 1231 (void *)"socketfile", RSRC_CONF,
1220 "<b>(Deprecated) Use LogSQLDBParam socketfile socket.</b> Name of the file to employ for socket connections to database") 1232 "<b>(Deprecated) Use LogSQLDBParam socketfile socket.</b> Name of the file to employ for socket connections to database")
1221 , 1233 ,
1222 AP_INIT_TAKE1("LogSQLTCPPort", set_dbparam_slot, 1234 AP_INIT_TAKE1("LogSQLTCPPort", set_dbparam_slot,
1223 (void *)"port", RSRC_CONF, 1235 (void *)"port", RSRC_CONF,
1224 "<b>(Deprecated) Use LogSQLDBParam port port.</b> Port number to use for TCP connections to database, defaults to 3306 if not set") 1236 "<b>(Deprecated) Use LogSQLDBParam port port.</b> Port number to use for TCP connections to database, defaults to 3306 if not set")
1225 , 1237 ,