From: Bert Hubert Date: Sat, 6 Oct 2012 10:58:38 +0000 (+0000) Subject: gmysql-client can now be used to select which 'group' we connect as to MySQL. Continu... X-Git-Tag: auth-3.2-rc1~112 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3d9b0007d08c00ff5026b643434b9f9261b1aca5;p=thirdparty%2Fpdns.git gmysql-client can now be used to select which 'group' we connect as to MySQL. Continues to default to 'client'. Thanks to Kees Monshouwer for contributing this patch, which closes ticket 463. Please check! git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2770 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/modules/gmysqlbackend/gmysqlbackend.cc b/modules/gmysqlbackend/gmysqlbackend.cc index 315e7a30b8..c9cf599713 100644 --- a/modules/gmysqlbackend/gmysqlbackend.cc +++ b/modules/gmysqlbackend/gmysqlbackend.cc @@ -26,7 +26,8 @@ gMySQLBackend::gMySQLBackend(const string &mode, const string &suffix) : GSQLBa getArgAsNum("port"), getArg("socket"), getArg("user"), - getArg("password"))); + getArg("password"), + getArg("group"))); } @@ -50,6 +51,7 @@ public: declare(suffix,"port","Database backend port to connect to","0"); declare(suffix,"socket","Pdns backend socket to connect to",""); declare(suffix,"password","Pdns backend password to connect with",""); + declare(suffix,"group", "Pdns backend MySQL 'group' to connect as", "client"); declare(suffix,"dnssec","Assume DNSSEC Schema is in place","no"); declare(suffix,"basic-query","Basic query","select content,ttl,prio,type,domain_id,name from records where type='%s' and name='%s'"); diff --git a/modules/gmysqlbackend/smysql.cc b/modules/gmysqlbackend/smysql.cc index 42b6180cee..987adbf4b7 100644 --- a/modules/gmysqlbackend/smysql.cc +++ b/modules/gmysqlbackend/smysql.cc @@ -14,15 +14,14 @@ bool SMySQL::s_dolog; pthread_mutex_t SMySQL::s_myinitlock = PTHREAD_MUTEX_INITIALIZER; SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const string &msocket, const string &user, - const string &password) + const string &password, const string &group) { { Lock l(&s_myinitlock); mysql_init(&d_db); - mysql_options(&d_db, MYSQL_READ_DEFAULT_GROUP, "client"); - my_bool reconnect = 1; #if MYSQL_VERSION_ID >= 50013 + my_bool reconnect = 1; mysql_options(&d_db, MYSQL_OPT_RECONNECT, &reconnect); #endif @@ -31,12 +30,15 @@ SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const mysql_options(&d_db, MYSQL_OPT_READ_TIMEOUT, &timeout); mysql_options(&d_db, MYSQL_OPT_WRITE_TIMEOUT, &timeout); #endif + + mysql_options(&d_db, MYSQL_READ_DEFAULT_GROUP, &group); - if (!mysql_real_connect(&d_db, host.empty() ? 0 : host.c_str(), - user.empty() ? 0 : user.c_str(), - password.empty() ? 0 : password.c_str(), - database.c_str(), port, - msocket.empty() ? 0 : msocket.c_str(), + if (!mysql_real_connect(&d_db, host.empty() ? NULL : host.c_str(), + user.empty() ? NULL : user.c_str(), + password.empty() ? NULL : password.c_str(), + database.empty() ? NULL : database.c_str(), + port, + msocket.empty() ? NULL : msocket.c_str(), CLIENT_MULTI_RESULTS)) { throw sPerrorException("Unable to connect to database"); diff --git a/modules/gmysqlbackend/smysql.hh b/modules/gmysqlbackend/smysql.hh index edb36456bd..4be990c123 100644 --- a/modules/gmysqlbackend/smysql.hh +++ b/modules/gmysqlbackend/smysql.hh @@ -12,8 +12,8 @@ class SMySQL : public SSql { public: SMySQL(const string &database, const string &host="", uint16_t port=0, - const string &msocket="",const string &user="", - const string &password=""); + const string &msocket="",const string &user="", + const string &password="", const string &group=""); ~SMySQL();