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! ;) */
21 #include "inspircd_config.h"
23 #include "inspircd_io.h"
24 #include "inspircd_util.h"
26 #include <sys/errno.h>
27 #include <sys/ioctl.h>
28 #include <sys/utsname.h>
33 #include <ext/hash_map>
51 #include "inspstring.h"
54 #include <sys/types.h>
55 #include <sys/socket.h>
58 #include <netinet/in.h>
61 #include "helperfuncs.h"
64 extern int MaxWhoResults;
66 extern std::vector<Module*> modules;
67 extern std::vector<std::string> module_names;
68 extern std::vector<ircd_module*> factory;
72 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
73 typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, irc::StrHashComp> chan_hash;
74 typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp> address_cache;
75 typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp> whowas_hash;
76 typedef std::deque<command_t> command_table;
78 extern user_hash clientlist;
79 extern chan_hash chanlist;
80 extern whowas_hash whowas;
81 extern command_table cmdlist;
83 extern ClassVector Classes;
85 extern char DNSServer[MAXBUF];
86 long max_fd_alloc = 0;
90 //enum LookupState { reverse, forward };
102 log(DEBUG,"Create class Lookup");
108 log(DEBUG,"Reset class Lookup");
113 log(DEBUG,"Delete class Lookup");
116 bool DoLookup(std::string nick)
119 userrec* usr = Find(nick);
122 log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
123 resolver1.SetNS(std::string(DNSServer));
124 if (!resolver1.ReverseLookup(std::string(usr->host)))
126 log(DEBUG,"ReverseLookup didnt return true, we're outta here");
129 strlcpy(u,nick.c_str(),NICKMAX);
132 log(DEBUG,"We couldnt find that user");
140 log(DEBUG,"Doing forward lookup here with host %s",hostname.c_str());
141 // doing forward lookup
143 if (resolver2.HasResult())
145 log(DEBUG,"resolver2 has result");
146 if (resolver2.GetFD() != 0)
148 std::string ip = resolver2.GetResultIP();
149 log(DEBUG,"FORWARD RESULT! %s",ip.c_str());
154 if (usr->registered > 3)
156 log(DEBUG,"Point 1: Returning true as usr->dns_done is true");
157 usr->dns_done = true;
160 if ((hostname != "") && (usr->registered != 7))
162 if (std::string(usr->ip) == ip)
164 strlcpy(usr->host,hostname.c_str(),MAXBUF);
165 strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
166 log(DEBUG,"Forward and reverse match, assigning hostname");
170 log(DEBUG,"AWOOGA! Forward lookup doesn't match reverse: R='%s',F='%s',IP='%s'",hostname.c_str(),ip.c_str(),usr->ip);
172 usr->dns_done = true;
182 log(DEBUG,"Point 2: Returning true");
183 usr->dns_done = true;
188 log(DEBUG,"Returning false in forward");
193 // doing reverse lookup
195 if (resolver1.HasResult())
198 if ((usr) && (usr->dns_done))
200 if (resolver1.GetFD() != 0)
202 hostname = resolver1.GetResult();
205 if ((usr->registered > 3) || (hostname == ""))
207 log(DEBUG,"Hostname is blank and user->registered > 3, returning true and setting done");
208 usr->dns_done = true;
214 log(DEBUG,"Starting forwardlookup now for host '%s'...",hostname.c_str());
215 resolver2.ForwardLookup(hostname);
220 log(DEBUG,"Returning false");
226 userrec* usr = Find(u);
237 bool lookup_dns(std::string nick)
239 userrec* u = Find(nick);
242 // place a new user into the queue...
243 log(DEBUG,"Queueing DNS lookup for %s",u->nick);
244 WriteServ(u->fd,"NOTICE Auth :Looking up your hostname...");
246 if (L.DoLookup(nick))
248 for (int j = 0; j < 255; j++)
250 if (!dnsq[j].GetFD())
256 // calculate the maximum value, this saves cpu time later
257 for (int p = 0; p < 255; p++)
271 // do we have items in the queue?
272 for (int j = 0; j <= max_fd_alloc; j++)
274 // are any ready, or stale?
283 // looks like someones freed an item, recalculate end of list.
284 if ((!dnsq[max_fd_alloc].GetFD()) && (max_fd_alloc != 0))
285 for (int p = 0; p < 255; p++)