Permalink
Browse files

make isMaster ip check more tollerant for different ipv6 notations

::1 and 0::1 now match

fixes #1174
  • Loading branch information...
1 parent 6f99678 commit 0c13e45a3d429a26d9a326612a0b80e2e6a6ca79 @mind04 mind04 committed with mind04 Dec 22, 2013
Showing with 15 additions and 19 deletions.
  1. +15 −19 pdns/backends/gsql/gsqlbackend.cc
@@ -74,34 +74,30 @@ void GSQLBackend::setFresh(uint32_t domain_id)
bool GSQLBackend::isMaster(const string &domain, const string &ip)
{
- char output[1024];
- snprintf(output,sizeof(output)-1,
- d_MasterOfDomainsZoneQuery.c_str(),
- sqlEscape(domain).c_str());
+ string query = (boost::format(d_MasterOfDomainsZoneQuery) % sqlEscape(domain)).str();
+
try {
- d_db->doQuery(output, d_result);
+ d_db->doQuery(query, d_result);
}
catch (SSqlException &e) {
throw PDNSException("GSQLBackend unable to retrieve list of master domains: "+e.txtReason());
}
- if(d_result.empty())
- return 0;
+ if(!d_result.empty()) {
+
+ // we can have multiple masters separated by commas
+ vector<string> masters;
+ stringtok(masters, d_result[0][0], " ,\t");
- // we can have multiple masters separated by commas
- vector<string> masters;
- stringtok(masters, d_result[0][0], " ,\t");
- for(vector<string>::const_iterator iter=masters.begin(); iter != masters.end(); ++iter) {
- // we can also have masters with a port specified (which we ignore here)
- ServiceTuple st;
- parseService(*iter, st);
- if (!strcmp(ip.c_str(), st.host.c_str())) {
- return 1;
- }
+ BOOST_FOREACH(const string master, masters) {
+ const ComboAddress caMaster(master);
+ if(ip == caMaster.toString())
+ return true;
+ }
}
- // if no masters matched then this is not a master
- return 0;
+ // no matching master
+ return false;
}
bool GSQLBackend::setMaster(const string &domain, const string &ip)

0 comments on commit 0c13e45

Please sign in to comment.