Imported Debian patch 0.60.1-1
[hcoop/debian/courier-authlib.git] / authmysqllib.c
index dc76ef4..40be961 100644 (file)
@@ -27,7 +27,7 @@
 #define                SV_BEGIN_LEN            ((sizeof(SV_BEGIN_MARK))-1)
 #define                SV_END_LEN              ((sizeof(SV_END_MARK))-1)
 
-static const char rcsid[]="$Id: authmysqllib.c,v 1.44 2007/02/10 02:51:06 mrsam Exp $";
+static const char rcsid[]="$Id: authmysqllib.c,v 1.45 2007/10/07 02:50:45 mrsam Exp $";
 
 /* siefca@pld.org.pl */
 struct var_data {                      
@@ -779,6 +779,43 @@ static const char query[]=
                }
        }
 
+/* Anton Dobkin <anton@viansib.ru>, VIAN, Ltd. */
+#if MYSQL_VERSION_ID >= 41000    
+       const char *character_set=read_env("MYSQL_CHARACTER_SET");
+    
+        if(character_set){
+            
+           char *character_set_buf;
+               
+            character_set_buf=malloc(strlen(character_set)+11);
+                       
+           if (!character_set_buf)
+            {
+               perror("malloc");
+               return (0);
+           }
+                                                   
+           strcpy(character_set_buf, "SET NAMES ");
+           strcat(character_set_buf, character_set);
+                                                               
+            DPRINTF("Install of a character set for MySQL. SQL query: SET NAMES %s", character_set);   
+                                                                       
+            if(mysql_query (mysql, character_set_buf))
+            {    
+                err("Install of a character set for MySQL is failed: %s MYSQL_CHARACTER_SET: may be invalid character set", mysql_error(mysql));
+               auth_mysql_cleanup();
+                           
+               if (do_connect())
+               {
+                   free(character_set_buf);
+                   return (0);
+               }
+            }
+           
+           free(character_set_buf);
+        }
+#endif 
+
        DPRINTF("SQL query: %s", querybuf);
        if (mysql_query (mysql, querybuf))
        {