diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-02 21:04:15 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-02 21:04:15 +0000 |
commit | e0e0338b6b7cee98540bb28a7f1c90e84bb0c5db (patch) | |
tree | dc6768a284b0d8ab0402ab5883a06b1b293c73a2 /src | |
parent | 7af42fd63e09131bbd24636f4c6d631049427d2c (diff) |
Fixes for dns queueing, timeout functions etc moved to more sensible place
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@956 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.cpp | 4 | ||||
-rw-r--r-- | src/dns.cpp | 11 | ||||
-rw-r--r-- | src/dnsqueue.cpp | 24 | ||||
-rw-r--r-- | src/inspircd.cpp | 62 |
4 files changed, 40 insertions, 61 deletions
diff --git a/src/commands.cpp b/src/commands.cpp index a52142ae7..92798377d 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1643,7 +1643,9 @@ void handle_nick(char **parameters, int pcnt, userrec *user) user->registered = (user->registered | 2); // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change // and unless we're lucky we'll get a duff one later on. - lookup_dns(user->nick); + user->dns_done = (!lookup_dns(user->nick)); + if (user->dns_done) + log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick); } if (user->registered == 3) { diff --git a/src/dns.cpp b/src/dns.cpp index a1287e499..c3d7cd786 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -212,7 +212,10 @@ static int dns_send_requests(const s_header *h, const s_connection *s, const int memcpy(&addr4.sin_addr,&servers4[i],sizeof(addr4.sin_addr)); addr4.sin_family = AF_INET; addr4.sin_port = htons(DNS_PORT); - sendto(s->fd, payload, l + 12, 0, (sockaddr *) &addr4, sizeof(addr4)); + if (sendto(s->fd, payload, l + 12, 0, (sockaddr *) &addr4, sizeof(addr4)) == -1) + { + return -1; + } } return 0; @@ -689,10 +692,12 @@ bool DNS::ReverseLookup(std::string ip) { binip = dns_aton4(ip.c_str()); if (binip == NULL) { - fprintf(stderr,"invalid IP address.\n"); - return 2; + return false; } this->fd = dns_getname4(binip); + if (this->fd == -1) + return false; + return true; } bool DNS::ForwardLookup(std::string host) diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 043ee8d4f..71ab99019 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -188,16 +188,19 @@ public: delete resolver; } - Lookup(std::string nick) + bool DoLookup(std::string nick) { userrec* usr = Find(nick); if (usr) { log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer); resolver = new DNS(std::string(DNSServer)); - resolver->ReverseLookup(std::string(usr->host)); + if (!resolver->ReverseLookup(std::string(usr->host))) + return false; strlcpy(u,nick.c_str(),NICKMAX); + return true; } + return false; } bool Done() @@ -257,15 +260,22 @@ bool lookup_dns(std::string nick) // place a new user into the queue... log(DEBUG,"Queueing DNS lookup for %s",u->nick); WriteServ(u->fd,"NOTICE Auth :Looking up your hostname..."); - Lookup L(nick); - for (int j = 0; j < MAXBUF; j++) + Lookup L; + if (L.DoLookup(nick)) { - if (!dnsq[j].GetFD()) + for (int j = 0; j < MAXBUF; j++) { - dnsq[j] = L; - return true; + if (!dnsq[j].GetFD()) + { + dnsq[j] = L; + return true; + } } } + else + { + return false; + } } return false; } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 1a0e9b681..53ac1dfab 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -98,8 +98,6 @@ std::vector<std::string> module_names; extern std::vector<ircd_module*> factory; std::vector<int> fd_reap; -std::string pending_connects[MAXBUF]; - extern int MODCOUNT; bool nofork = false; @@ -2098,12 +2096,6 @@ userrec* ReHashNick(char* Old, char* New) clientlist[New] = oldnick->second; clientlist.erase(oldnick); - for (long i = 0; i < MAXBUF; i++) - { - if (pending_connects[i] == std::string(Old)) - pending_connects[i] = std::string(New); - } - log(DEBUG,"ReHashNick: Nick rehashed as %s",New); return clientlist[New]; @@ -2423,36 +2415,6 @@ void FullConnectUser(userrec* user) NetSendToAll(buffer); } -// handles any connects where DNS isnt done yet, times out stale dns queries on users, and lets completed queries connect. -void HandlePendingConnects() -{ - for (long i = 0; i < MAXBUF; i++) - { - if (pending_connects[i] != "") - { - userrec* a = Find(pending_connects[i]); - if (a) - { - // this user's dns is done now. - if ((a->dns_done) && (a->registered >= 3)) - { - FullConnectUser(a); // attack! attack!.... - pending_connects[i] = ""; - return; // ...RUN AWAY! RUN AWAY! - } - // this users dns is NOT done, but its timed out. - if ((time(NULL) > a->signon) && (a->registered >= 3)) - { - WriteServ(a->fd,"NOTICE Auth :Failed to resolve your hostname, using your IP address instead."); - FullConnectUser(a); - pending_connects[i] = ""; - return; - } - } - } - } -} - /* shows the message of the day, and any other on-logon stuff */ void ConnectUser(userrec *user) { @@ -2461,15 +2423,6 @@ void ConnectUser(userrec *user) { FullConnectUser(user); } - else - { - // add them to the pending queue - for (int i = 0; i < MAXBUF; i++) - { - pending_connects[i] = std::string(user->nick); - break; - } - } } void handle_version(char **parameters, int pcnt, userrec *user) @@ -3448,9 +3401,6 @@ int InspIRCd(void) // poll dns queue dns_poll(); - // handle pending connects - HandlePendingConnects(); - user_hash::iterator count2 = clientlist.begin(); // *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue @@ -3580,6 +3530,18 @@ int InspIRCd(void) kill_link(count2->second,"Registration timeout"); goto label; } + if ((time(NULL) > count2->second->signon) && (count2->second->registered != 7)) + { + count2->second->dns_done = true; + FullConnectUser(count2->second); + goto label; + } + if ((count2->second->dns_done) && (count2->second->registered == 3)) // both NICK and USER... and DNS + { + WriteServ(count2->second->fd,"NOTICE Auth :Timed out when looking up your hostname!",ServerName); + FullConnectUser(count2->second); + goto label; + } if (((time(NULL)) > count2->second->nping) && (isnick(count2->second->nick)) && (count2->second->registered == 7)) { if ((!count2->second->lastping) && (count2->second->registered == 7)) |