mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 18:41:56 +01:00
compare host names by address lookup instead of simple string comparison
This commit is contained in:
parent
e6560c0da0
commit
2b6f6d6ce6
1 changed files with 45 additions and 3 deletions
|
@ -23,6 +23,8 @@
|
||||||
#include <my_getopt.h>
|
#include <my_getopt.h>
|
||||||
#include <mysql_version.h>
|
#include <mysql_version.h>
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
#include <NdbOut.hpp>
|
#include <NdbOut.hpp>
|
||||||
#include <mgmapi.h>
|
#include <mgmapi.h>
|
||||||
#include <mgmapi_configuration.hpp>
|
#include <mgmapi_configuration.hpp>
|
||||||
|
@ -127,6 +129,11 @@ struct Match
|
||||||
virtual int eval(NdbMgmHandle, const Iter&);
|
virtual int eval(NdbMgmHandle, const Iter&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct HostMatch : public Match
|
||||||
|
{
|
||||||
|
virtual int eval(NdbMgmHandle, const Iter&);
|
||||||
|
};
|
||||||
|
|
||||||
struct Apply
|
struct Apply
|
||||||
{
|
{
|
||||||
Apply() {}
|
Apply() {}
|
||||||
|
@ -297,9 +304,10 @@ parse_where(Vector<Match*>& where, int &argc, char**& argv)
|
||||||
Match m;
|
Match m;
|
||||||
if(g_host)
|
if(g_host)
|
||||||
{
|
{
|
||||||
m.m_key = CFG_NODE_HOST;
|
HostMatch *m = new HostMatch;
|
||||||
m.m_value.assfmt("%s", g_host);
|
m->m_key = CFG_NODE_HOST;
|
||||||
where.push_back(new Match(m));
|
m->m_value.assfmt("%s", g_host);
|
||||||
|
where.push_back(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(g_type)
|
if(g_type)
|
||||||
|
@ -375,6 +383,40 @@ Match::eval(NdbMgmHandle h, const Iter& iter)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
HostMatch::eval(NdbMgmHandle h, const Iter& iter)
|
||||||
|
{
|
||||||
|
const char* valc;
|
||||||
|
|
||||||
|
if(iter.get(m_key, &valc) == 0)
|
||||||
|
{
|
||||||
|
struct hostent *h1, *h2;
|
||||||
|
|
||||||
|
h1 = gethostbyname(m_value.c_str());
|
||||||
|
if (h1 == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 = gethostbyname(valc);
|
||||||
|
if (h2 == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (h1->h_addrtype != h2->h_addrtype) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (h1->h_length != h2->h_length)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 == memcmp(h1->h_addr, h2->h_addr, h1->h_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Apply::apply(NdbMgmHandle h, const Iter& iter)
|
Apply::apply(NdbMgmHandle h, const Iter& iter)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue