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"
27 #include <sys/errno.h>
28 #include <sys/ioctl.h>
29 #include <sys/utsname.h>
34 #include <ext/hash_map>
46 #include "connection.h"
58 #include "inspstring.h"
62 #include <sys/types.h>
63 #include <sys/socket.h>
66 #include <netinet/in.h>
73 #include "helperfuncs.h"
76 extern int MaxWhoResults;
78 extern std::vector<Module*> modules;
79 extern std::vector<std::string> module_names;
80 extern std::vector<ircd_module*> factory;
81 extern std::vector<int> fd_reap;
85 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, StrHashComp> user_hash;
86 typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, StrHashComp> chan_hash;
87 typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, InAddr_HashComp> address_cache;
88 typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, StrHashComp> whowas_hash;
89 typedef std::deque<command_t> command_table;
91 extern user_hash clientlist;
92 extern chan_hash chanlist;
93 extern whowas_hash whowas;
94 extern command_table cmdlist;
96 extern ClassVector Classes;
98 extern char DNSServer[MAXBUF];
99 long max_fd_alloc = 0;
122 bool DoLookup(std::string nick)
124 userrec* usr = Find(nick);
127 log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
128 resolver.SetNS(std::string(DNSServer));
129 if (!resolver.ReverseLookup(std::string(usr->host)))
131 strlcpy(u,nick.c_str(),NICKMAX);
140 if (resolver.HasResult())
142 if (resolver.GetFD() != 0)
144 std::string hostname = resolver.GetResult();
145 log(DEBUG,"RESULT! %s",hostname.c_str());
149 if (usr->registered > 3)
151 usr->dns_done = true;
154 if ((hostname != "") && (usr->registered != 7))
156 strlcpy(usr->host,hostname.c_str(),MAXBUF);
157 strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
158 WriteServ(usr->fd,"NOTICE Auth :Resolved your hostname: %s",hostname.c_str());
159 usr->dns_done = true;
162 usr->dns_done = true;
170 usr->dns_done = true;
179 userrec* usr = Find(u);
190 bool lookup_dns(std::string nick)
192 userrec* u = Find(nick);
195 // place a new user into the queue...
196 log(DEBUG,"Queueing DNS lookup for %s",u->nick);
197 WriteServ(u->fd,"NOTICE Auth :Looking up your hostname...");
199 if (L.DoLookup(nick))
201 for (int j = 0; j < 255; j++)
203 if (!dnsq[j].GetFD())
209 // calculate the maximum value, this saves cpu time later
210 for (int p = 0; p < 255; p++)
224 // do we have items in the queue?
225 for (int j = 0; j <= max_fd_alloc; j++)
227 // are any ready, or stale?
236 // looks like someones freed an item, recalculate end of list.
237 if ((!dnsq[max_fd_alloc].GetFD()) && (max_fd_alloc != 0))
238 for (int p = 0; p < 255; p++)