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>
75 #define nspace __gnu_cxx
80 extern int MaxWhoResults;
82 extern std::vector<Module*> modules;
83 extern std::vector<std::string> module_names;
84 extern std::vector<ircd_module*> factory;
85 extern std::vector<int> fd_reap;
92 template<> struct hash<in_addr>
94 template<> struct nspace::hash<in_addr>
97 size_t operator()(const struct in_addr &a) const
100 memcpy(&q,&a,sizeof(size_t));
105 template<> struct hash<string>
107 template<> struct nspace::hash<string>
110 size_t operator()(const string &s) const
113 static struct hash<const char *> strhash;
114 strlcpy(a,s.c_str(),MAXBUF);
125 bool operator()(const string& s1, const string& s2) const
127 char a[MAXBUF],b[MAXBUF];
128 strlcpy(a,s1.c_str(),MAXBUF);
129 strlcpy(b,s2.c_str(),MAXBUF);
130 return (strcasecmp(a,b) == 0);
135 struct InAddr_HashComp
138 bool operator()(const in_addr &s1, const in_addr &s2) const
143 memcpy(&q,&s1,sizeof(size_t));
144 memcpy(&p,&s2,sizeof(size_t));
152 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, StrHashComp> user_hash;
153 typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, StrHashComp> chan_hash;
154 typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, InAddr_HashComp> address_cache;
155 typedef std::deque<command_t> command_table;
157 extern user_hash clientlist;
158 extern chan_hash chanlist;
159 extern user_hash whowas;
160 extern command_table cmdlist;
162 extern ClassVector Classes;
164 extern char DNSServer[MAXBUF];
165 long max_fd_alloc = 0;
192 bool DoLookup(std::string nick)
194 userrec* usr = Find(nick);
197 log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
198 resolver = new DNS(std::string(DNSServer));
199 if (!resolver->ReverseLookup(std::string(usr->host)))
201 strlcpy(u,nick.c_str(),NICKMAX);
210 if (resolver->HasResult())
212 if (resolver->GetFD() != 0)
214 std::string hostname = resolver->GetResult();
218 if (usr->registered > 3)
220 usr->dns_done = true;
223 if ((hostname != "") && (usr->registered != 7))
225 strlcpy(usr->host,hostname.c_str(),MAXBUF);
226 strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
227 WriteServ(usr->fd,"NOTICE Auth :Resolved your hostname: %s",hostname.c_str());
228 usr->dns_done = true;
231 usr->dns_done = true;
239 usr->dns_done = true;
248 userrec* usr = Find(u);
259 bool lookup_dns(std::string nick)
261 userrec* u = Find(nick);
264 // place a new user into the queue...
265 log(DEBUG,"Queueing DNS lookup for %s",u->nick);
266 WriteServ(u->fd,"NOTICE Auth :Looking up your hostname...");
268 if (L.DoLookup(nick))
270 for (int j = 0; j < MAXBUF; j++)
272 if (!dnsq[j].GetFD())
278 // calculate the maximum value, this saves cpu time later
279 for (int p = 0; p < MAXBUF; p++)
293 // do we have items in the queue?
294 for (int j = 0; j <= max_fd_alloc; j++)
296 // are any ready, or stale?
305 // looks like someones freed an item, recalculate end of list.
306 if ((!dnsq[max_fd_alloc].GetFD()) && (max_fd_alloc != 0))
307 for (int p = 0; p < MAXBUF; p++)