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*> modules;
69 extern std::vector<std::string> module_names;
70 extern std::vector<ircd_module*> factory;
74 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
75 typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, irc::StrHashComp> chan_hash;
76 typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp> address_cache;
77 typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp> whowas_hash;
78 typedef std::deque<command_t> command_table;
80 extern user_hash clientlist;
81 extern chan_hash chanlist;
82 extern whowas_hash whowas;
83 extern command_table cmdlist;
85 extern ClassVector Classes;
87 extern char DNSServer[MAXBUF];
88 long max_fd_alloc = 0;
111 bool DoLookup(std::string nick)
113 userrec* usr = Find(nick);
116 log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
117 resolver.SetNS(std::string(DNSServer));
118 if (!resolver.ReverseLookup(std::string(usr->host)))
120 strlcpy(u,nick.c_str(),NICKMAX);
129 if (resolver.HasResult())
131 if (resolver.GetFD() != 0)
133 std::string hostname = resolver.GetResult();
134 log(DEBUG,"RESULT! %s",hostname.c_str());
138 if (usr->registered > 3)
140 usr->dns_done = true;
143 if ((hostname != "") && (usr->registered != 7))
145 strlcpy(usr->host,hostname.c_str(),MAXBUF);
146 strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
147 WriteServ(usr->fd,"NOTICE Auth :Resolved your hostname: %s",hostname.c_str());
148 usr->dns_done = true;
151 usr->dns_done = true;
159 usr->dns_done = true;
168 userrec* usr = Find(u);
179 bool lookup_dns(std::string nick)
181 userrec* u = Find(nick);
184 // place a new user into the queue...
185 log(DEBUG,"Queueing DNS lookup for %s",u->nick);
186 WriteServ(u->fd,"NOTICE Auth :Looking up your hostname...");
188 if (L.DoLookup(nick))
190 for (int j = 0; j < 255; j++)
192 if (!dnsq[j].GetFD())
198 // calculate the maximum value, this saves cpu time later
199 for (int p = 0; p < 255; p++)
213 // do we have items in the queue?
214 for (int j = 0; j <= max_fd_alloc; j++)
216 // are any ready, or stale?
225 // looks like someones freed an item, recalculate end of list.
226 if ((!dnsq[max_fd_alloc].GetFD()) && (max_fd_alloc != 0))
227 for (int p = 0; p < 255; p++)