1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 /* Now with added unF! ;) */
22 #include "inspircd_io.h"
23 #include "inspircd_util.h"
24 #include "inspircd_config.h"
26 #include <sys/errno.h>
27 #include <sys/ioctl.h>
28 #include <sys/utsname.h>
33 #include <ext/hash_map>
41 #include "connection.h"
53 #include "inspstring.h"
56 #include <sys/types.h>
57 #include <sys/socket.h>
60 #include <netinet/in.h>
63 #include "helperfuncs.h"
66 extern int MaxWhoResults;
68 extern std::vector<Module*, __single_client_alloc> modules;
69 extern std::vector<std::string, __single_client_alloc> module_names;
70 extern std::vector<ircd_module*, __single_client_alloc> factory;
71 extern std::vector<int, __single_client_alloc> fd_reap;
75 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp, __single_client_alloc> user_hash;
76 typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, irc::StrHashComp, __single_client_alloc> chan_hash;
77 typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp, __single_client_alloc> address_cache;
78 typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp, __single_client_alloc> whowas_hash;
79 typedef std::deque<command_t, __single_client_alloc> command_table;
81 extern user_hash clientlist;
82 extern chan_hash chanlist;
83 extern whowas_hash whowas;
84 extern command_table cmdlist;
86 extern ClassVector Classes;
88 extern char DNSServer[MAXBUF];
89 long max_fd_alloc = 0;
112 bool DoLookup(std::string nick)
114 userrec* usr = Find(nick);
117 log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
118 resolver.SetNS(std::string(DNSServer));
119 if (!resolver.ReverseLookup(std::string(usr->host)))
121 strlcpy(u,nick.c_str(),NICKMAX);
130 if (resolver.HasResult())
132 if (resolver.GetFD() != 0)
134 std::string hostname = resolver.GetResult();
135 log(DEBUG,"RESULT! %s",hostname.c_str());
139 if (usr->registered > 3)
141 usr->dns_done = true;
144 if ((hostname != "") && (usr->registered != 7))
146 strlcpy(usr->host,hostname.c_str(),MAXBUF);
147 strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
148 WriteServ(usr->fd,"NOTICE Auth :Resolved your hostname: %s",hostname.c_str());
149 usr->dns_done = true;
152 usr->dns_done = true;
160 usr->dns_done = true;
169 userrec* usr = Find(u);
180 bool lookup_dns(std::string nick)
182 userrec* u = Find(nick);
185 // place a new user into the queue...
186 log(DEBUG,"Queueing DNS lookup for %s",u->nick);
187 WriteServ(u->fd,"NOTICE Auth :Looking up your hostname...");
189 if (L.DoLookup(nick))
191 for (int j = 0; j < 255; j++)
193 if (!dnsq[j].GetFD())
199 // calculate the maximum value, this saves cpu time later
200 for (int p = 0; p < 255; p++)
214 // do we have items in the queue?
215 for (int j = 0; j <= max_fd_alloc; j++)
217 // are any ready, or stale?
226 // looks like someones freed an item, recalculate end of list.
227 if ((!dnsq[max_fd_alloc].GetFD()) && (max_fd_alloc != 0))
228 for (int p = 0; p < 255; p++)