The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

DNSBLResolver Class Reference

Resolver for CGI:IRC hostnames encoded in ident/GECOS. More...

Inheritance diagram for DNSBLResolver:

Inheritance graph
[legend]
Collaboration diagram for DNSBLResolver:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DNSBLResolver (Module *me, InspIRCd *ServerInstance, const std::string &hostname, userrec *u, int userfd, DNSBLConfEntry *conf, bool &cached)
virtual void OnLookupComplete (const std::string &result, unsigned int ttl, bool cached)
 When your lookup completes, this method will be called.
virtual void OnError (ResolverError e, const std::string &errormessage)
 If an error occurs (such as NXDOMAIN, no domain name found) then this method will be called.
virtual ~DNSBLResolver ()

Private Attributes

int theirfd
userrecthem
DNSBLConfEntryConfEntry

Detailed Description

Resolver for CGI:IRC hostnames encoded in ident/GECOS.

Definition at line 47 of file m_dnsbl.cpp.


Constructor & Destructor Documentation

DNSBLResolver::DNSBLResolver Module me,
InspIRCd ServerInstance,
const std::string hostname,
userrec u,
int  userfd,
DNSBLConfEntry conf,
bool &  cached
[inline]
 

Definition at line 55 of file m_dnsbl.cpp.

References ConfEntry, theirfd, and them.

00056                 : Resolver(ServerInstance, hostname, DNS_QUERY_A, cached, me)
00057         {
00058                 theirfd = userfd;
00059                 them = u;
00060                 ConfEntry = conf;
00061         }

virtual DNSBLResolver::~DNSBLResolver  )  [inline, virtual]
 

Definition at line 154 of file m_dnsbl.cpp.

00155         {
00156         }


Member Function Documentation

virtual void DNSBLResolver::OnError ResolverError  e,
const std::string errormessage
[inline, virtual]
 

If an error occurs (such as NXDOMAIN, no domain name found) then this method will be called.

Parameters:
e A ResolverError enum containing the error type which has occured.
errormessage The error text of the error that occured.

Reimplemented from Resolver.

Definition at line 150 of file m_dnsbl.cpp.

00151         {
00152         }

virtual void DNSBLResolver::OnLookupComplete const std::string result,
unsigned int  ttl,
bool  cached
[inline, virtual]
 

When your lookup completes, this method will be called.

Parameters:
result The resulting DNS lookup, either an IP address or a hostname.
ttl The time-to-live value of the result, in the instance of a cached result, this is the number of seconds remaining before refresh/expiry.
cached True if the result is a cached result, false if it was requested from the DNS server.

Implements Resolver.

Definition at line 63 of file m_dnsbl.cpp.

References XLineManager::add_gline(), XLineManager::add_kline(), XLineManager::add_zline(), APPLY_GLINES, APPLY_KLINES, XLineManager::apply_lines(), APPLY_ZLINES, DNSBLConfEntry::banaction, DNSBLConfEntry::bitmask, ConfEntry, InspIRCd::Config, DNSBLConfEntry::duration, FOREACH_MOD, userrec::GetFullRealHost(), userrec::GetIPString(), SocketEngine::GetRef(), DNSBLConfEntry::I_GLINE, DNSBLConfEntry::I_KILL, DNSBLConfEntry::I_KLINE, I_OnAddGLine, I_OnAddKLine, I_OnAddZLine, DNSBLConfEntry::I_UNKNOWN, DNSBLConfEntry::I_ZLINE, DNSBLConfEntry::name, userrec::QuitUser(), DNSBLConfEntry::reason, InspIRCd::SE, Resolver::ServerInstance, ServerConfig::ServerName, DNSBLConfEntry::stats_hits, DNSBLConfEntry::stats_misses, theirfd, them, InspIRCd::WriteOpers(), and InspIRCd::XLines.

00064         {
00065                 /* Check the user still exists */
00066                 if ((them) && (them == ServerInstance->SE->GetRef(theirfd)))
00067                 {
00068                         // Now we calculate the bitmask: 256*(256*(256*a+b)+c)+d
00069                         if(result.length())
00070                         {
00071                                 unsigned int bitmask = 0;
00072                                 bool show = false;
00073                                 in_addr resultip;
00074 
00075                                 /* Convert the result to an in_addr (we can gaurantee we got ipv4)
00076                                  * Whoever did the loop that was here before, I AM CONFISCATING
00077                                  * YOUR CRACKPIPE. you know who you are. -- Brain
00078                                  */
00079                                 inet_aton(result.c_str(), &resultip);
00080                                 bitmask = resultip.s_addr >> 24; /* Last octet (network byte order */
00081 
00082                                 bitmask &= ConfEntry->bitmask;
00083 
00084                                 if (bitmask != 0)
00085                                 {
00086                                         std::string reason = ConfEntry->reason;
00087                                         std::string::size_type x = reason.find("%ip%");
00088                                         while (x != std::string::npos)
00089                                         {
00090                                                 reason.erase(x, 4);
00091                                                 reason.insert(x, them->GetIPString());
00092                                                 x = reason.find("%ip%");
00093                                         }
00094 
00095                                         ConfEntry->stats_hits++;
00096 
00097                                         switch (ConfEntry->banaction)
00098                                         {
00099                                                 case DNSBLConfEntry::I_KILL:
00100                                                 {
00101                                                         userrec::QuitUser(ServerInstance, them, std::string("Killed (") + reason + ")");
00102                                                         break;
00103                                                 }
00104                                                 case DNSBLConfEntry::I_KLINE:
00105                                                 {
00106                                                         std::string ban = std::string("*@") + them->GetIPString();
00107                                                         if (show)
00108                                                                 ServerInstance->XLines->apply_lines(APPLY_KLINES);                                                              
00109                                                         show = ServerInstance->XLines->add_kline(ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(), ban.c_str());
00110                                                         FOREACH_MOD(I_OnAddKLine,OnAddKLine(ConfEntry->duration, NULL, reason, ban));
00111                                                         break;
00112                                                 }
00113                                                 case DNSBLConfEntry::I_GLINE:
00114                                                 {
00115                                                         std::string ban = std::string("*@") + them->GetIPString();
00116                                                         show = ServerInstance->XLines->add_gline(ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(), ban.c_str());
00117                                                         if (show)
00118                                                                 ServerInstance->XLines->apply_lines(APPLY_GLINES);
00119                                                         FOREACH_MOD(I_OnAddGLine,OnAddGLine(ConfEntry->duration, NULL, reason, ban));
00120                                                         break;
00121                                                 }
00122                                                 case DNSBLConfEntry::I_ZLINE:
00123                                                 {
00124                                                         show = ServerInstance->XLines->add_zline(ConfEntry->duration, ServerInstance->Config->