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"
63 #include "socketengine.h"
65 extern SocketEngine* SE;
67 extern int MaxWhoResults;
69 extern std::vector<Module*> modules;
70 extern std::vector<std::string> module_names;
71 extern std::vector<ircd_module*> factory;
75 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
76 typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, irc::StrHashComp> chan_hash;
77 typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp> address_cache;
78 typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp> whowas_hash;
79 typedef std::deque<command_t> 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;
93 //enum LookupState { reverse, forward };
100 std::string hostname;
110 log(DEBUG,"Reset class Lookup");
117 bool DoLookup(std::string nick)
120 userrec* usr = Find(nick);
123 log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
124 resolver1.SetNS(std::string(DNSServer));
125 if (!resolver1.ReverseLookup(std::string(usr->host)))
127 log(DEBUG,"ReverseLookup didnt return true, we're outta here");
130 strlcpy(u,nick.c_str(),NICKMAX);
133 log(DEBUG,"We couldnt find that user");
137 bool Done(int fdcheck)
141 log(DEBUG,"Doing forward lookup here with host %s",hostname.c_str());
142 // doing forward lookup
144 if (resolver2.HasResult(fdcheck))
146 log(DEBUG,"resolver2 has result");
147 if (resolver2.GetFD() != 0)
149 std::string ip = resolver2.GetResultIP();
150 log(DEBUG,"FORWARD RESULT! %s",ip.c_str());
155 if (usr->registered > 3)
157 log(DEBUG,"Point 1: Returning true as usr->dns_done is true");
158 usr->dns_done = true;
161 if ((hostname != "") && (usr->registered != 7))
163 if (std::string(usr->ip) == ip)
165 strlcpy(usr->host,hostname.c_str(),MAXBUF);
166 strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
167 log(DEBUG,"Forward and reverse match, assigning hostname");
171 log(DEBUG,"AWOOGA! Forward lookup doesn't match reverse: R='%s',F='%s',IP='%s'",hostname.c_str(),ip.c_str(),usr->ip);
173 usr->dns_done = true;
183 log(DEBUG,"Point 2: Returning true");
184 usr->dns_done = true;
189 log(DEBUG,"Returning false in forward");
194 // doing reverse lookup
196 if (resolver1.HasResult(fdcheck))
199 if ((usr) && (usr->dns_done))
201 if (resolver1.GetFD() != 0)
203 hostname = resolver1.GetResult();
206 if ((usr->registered > 3) || (hostname == ""))
208 log(DEBUG,"Hostname is blank and user->registered > 3, returning true and setting done");
209 usr->dns_done = true;
215 log(DEBUG,"Starting forwardlookup now for host '%s'...",hostname.c_str());
216 resolver2.ForwardLookup(hostname);
221 log(DEBUG,"Returning false");
227 userrec* usr = Find(u);
238 bool lookup_dns(std::string nick)
240 userrec* u = Find(nick);
243 // place a new user into the queue...
244 log(DEBUG,"Queueing DNS lookup for %s",u->nick);
245 WriteServ(u->fd,"NOTICE Auth :Looking up your hostname...");
247 if (L.DoLookup(nick))
249 for (int j = 0; j < 255; j++)
251 if (!dnsq[j].GetFD())
257 // calculate the maximum value, this saves cpu time later
258 for (int p = 0; p < 255; p++)
270 void dns_poll(int fdcheck)
272 // do we have items in the queue?
273 for (int j = 0; j <= max_fd_alloc; j++)
275 // are any ready, or stale?
278 if (dnsq[j].Done(fdcheck))
284 // looks like someones freed an item, recalculate end of list.
285 if ((!dnsq[max_fd_alloc].GetFD()) && (max_fd_alloc != 0))
286 for (int p = 0; p < 255; p++)