From a31886efbb89e21999b6442d074aa97ec7514c76 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Fri, 21 Nov 2008 16:07:54 +0000 Subject: [PATCH] Add support for specifying the connection character set via Auth_MySQL_CharacterSet --- debian/changelog | 6 +- debian/patches/00list | 1 + debian/patches/012-charset.dpatch | 126 ++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100755 debian/patches/012-charset.dpatch diff --git a/debian/changelog b/debian/changelog index c4844a2..5e78720 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,11 @@ mod-auth-mysql (4.3.9-10) unstable; urgency=low * Document disabling BasicAuth and basic group file in USAGE - [011-auth_basic.dpatch] (closes: Bug#502895, Bug#382242) + [011-auth_basic.dpatch] (closes: Bug#502895, Bug#382242) + * Add support for specifying the connection character set via + Auth_MySQL_CharacterSet [012-charset.dpatch] (closes: Bug#356530) - -- + -- Joey Schulze Fri, 21 Nov 2008 17:07:25 +0100 mod-auth-mysql (4.3.9-9) unstable; urgency=low diff --git a/debian/patches/00list b/debian/patches/00list index 4e02325..7c26cec 100644 --- a/debian/patches/00list +++ b/debian/patches/00list @@ -8,3 +8,4 @@ 009-port-int 010-enctype-apache 011-auth_basic +012-charset diff --git a/debian/patches/012-charset.dpatch b/debian/patches/012-charset.dpatch new file mode 100755 index 0000000..73d6bcb --- /dev/null +++ b/debian/patches/012-charset.dpatch @@ -0,0 +1,126 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 012-charset.dpatch by Joey Schulze +## +## DP: Add support for specifying the connection character set +## DP: via Auth_MySQL_CharacterSet. + +@DPATCH@ +diff -urNad mod-auth-mysql~/DIRECTIVES mod-auth-mysql/DIRECTIVES +--- mod-auth-mysql~/DIRECTIVES 2008-11-21 17:05:40.000000000 +0100 ++++ mod-auth-mysql/DIRECTIVES 2008-11-21 17:05:40.000000000 +0100 +@@ -74,6 +74,18 @@ + Auth_MySQL_DefaultDB + Synonym for Auth_MySQL_General_DB. + ++Auth_MySQL_CharacterSet ++ ++ Set the connection character set to the specified one. Otherwise no ++ particular character set is used when the connection is created. ++ This could cause problems with differently encoded strings and table ++ or column collations. The parameter must be a valid MySQL ++ character. It is mandatory if the character set used for tables/rows ++ differs from the default. ++ ++AuthMySQL_CharacterSet ++ Synonym for Auth_MySQL_CharacterSet. ++ + AuthName "" + Describes the data you're guarding. + +diff -urNad mod-auth-mysql~/mod_auth_mysql.c mod-auth-mysql/mod_auth_mysql.c +--- mod-auth-mysql~/mod_auth_mysql.c 2008-11-21 17:05:40.000000000 +0100 ++++ mod-auth-mysql/mod_auth_mysql.c 2008-11-21 17:05:50.000000000 +0100 +@@ -299,6 +299,7 @@ + char *db_user; + char *db_pwd; + char *db_name; ++ char *db_charset; + + MYSQL *dbh; + +@@ -344,6 +345,7 @@ + #else + static void + #endif ++ + auth_mysql_cleanup(void *ptr) + { + mysql_auth_config_rec *sec = ptr; +@@ -395,7 +397,7 @@ + sizeof(mysql_auth_config_rec)); + #endif + +- sec->db_name = sec->db_socket = sec->db_user = sec->db_pwd = NULL; ++ sec->db_name = sec->db_socket = sec->db_user = sec->db_pwd = sec->db_charset = NULL; + + sec->dbh = NULL; + /* When the memory for this connection record is cleaned, we must +@@ -804,6 +806,14 @@ + (void*)APR_OFFSETOF(mysql_auth_config_rec, db_name), + OR_AUTHCFG, "database name" ), + ++ AP_INIT_TAKE1( "Auth_MySQL_CharacterSet", ap_set_string_slot, ++ (void*)APR_OFFSETOF(mysql_auth_config_rec, db_charset), ++ OR_AUTHCFG, "character set" ), ++ ++ AP_INIT_TAKE1( "AuthMySQL_CharacterSet", ap_set_string_slot, ++ (void*)APR_OFFSETOF(mysql_auth_config_rec, db_charset), ++ OR_AUTHCFG, "character set" ), ++ + AP_INIT_TAKE1( "Auth_MySQL_Password_Table", ap_set_string_slot, + (void*)APR_OFFSETOF(mysql_auth_config_rec, user_table), + OR_AUTHCFG, "Name of the MySQL table containing the password/user-name combination" ), +@@ -1072,6 +1082,14 @@ + (void *) XtOffsetOf(mysql_auth_config_rec, db_name), + OR_AUTHCFG, TAKE1, "database name" }, + ++ { "Auth_MySQL_CharacterSet", ap_set_string_slot, ++ (void *) XtOffsetOf(mysql_auth_config_rec, db_charset), ++ OR_AUTHCFG, TAKE1, "character set" }, ++ ++ { "AuthMySQL_CharacterSet", ap_set_string_slot, ++ (void *) XtOffsetOf(mysql_auth_config_rec, db_charset), ++ OR_AUTHCFG, TAKE1, "character set" }, ++ + { "Auth_MySQL_Password_Table", ap_set_string_slot, + (void *) XtOffsetOf(mysql_auth_config_rec, user_table), + OR_AUTHCFG, TAKE1, "Name of the MySQL table containing the password/user-name combination" }, +@@ -1264,6 +1282,7 @@ + #if MYSQL_VERSION_ID >= 50013 + my_bool do_reconnect = 1; + #endif ++ char *query; + + APACHELOG(APLOG_DEBUG, r, "Opening DB connection for %s", sec->dir); + +@@ -1354,6 +1373,30 @@ + #endif + } + ++ if (sec->db_charset) { ++ APACHELOG(APLOG_DEBUG, r, ++ "Setting character set to %s", sec->db_charset); ++ ++ query = (char *) PSTRCAT(r->pool, "SET CHARACTER SET ", sec->db_charset, NULL); ++ if (!query) { ++ APACHELOG(APLOG_ERR, r, ++ "Failed to create query string - we're no good..."); ++ return -1; ++ } ++ ++ if (mysql_query(sec->dbh, query)) { ++ if (sec->dbh) ++ { ++ APACHELOG(APLOG_ERR, r, ++ "Query call failed: %s (%i)", mysql_error(sec->dbh), ++ mysql_errno(sec->dbh)); ++ } ++ ++ APACHELOG(APLOG_DEBUG, r, "Failed query was: [%s]", query); ++ return -1; ++ } ++ } ++ + /* W00t! We made it! */ + return 0; + } -- 2.20.1