1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDusermanager */
20 /* add a client connection to the sockets list */
21 void UserManager::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, int socketfamily, sockaddr* ip)
23 /* NOTE: Calling this one parameter constructor for User automatically
24 * allocates a new UUID and places it in the hash_map.
29 New = new User(Instance);
33 Instance->Log(DEFAULT,"*** WTF *** Duplicated UUID! -- Crack smoking monkies have been unleashed.");
34 Instance->WriteOpers("*** WARNING *** Duplicate UUID allocated!");
38 Instance->Log(DEBUG,"New user fd: %d", socket);
42 Instance->unregistered_count++;
46 if (socketfamily == AF_INET6)
47 inet_ntop(AF_INET6, &((const sockaddr_in6*)ip)->sin6_addr, ipaddr, sizeof(ipaddr));
50 inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr));
52 (*(Instance->clientlist))[New->uuid] = New;
54 /* The users default nick is their UUID */
55 strlcpy(New->nick, New->uuid, NICKMAX - 1);
57 New->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
58 /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
59 strcpy(New->ident, "unknown");
61 New->registered = REG_NONE;
62 New->signon = Instance->Time() + Instance->Config->dns_timeout;
65 New->SetSockAddr(socketfamily, ipaddr, port);
69 /* Smarter than your average bear^H^H^H^Hset of strlcpys. */
70 for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
71 New->dhost[j] = New->host[j] = *temp;
72 New->dhost[j] = New->host[j] = 0;
74 Instance->Users->AddLocalClone(New);
75 Instance->Users->AddGlobalClone(New);
78 * First class check. We do this again in FullConnect after DNS is done, and NICK/USER is recieved.
79 * See my note down there for why this is required. DO NOT REMOVE. :) -- w00t
81 ConnectClass* i = New->SetClass();
85 User::QuitUser(Instance, New, "Access denied by configuration");
90 * Check connect class settings and initialise settings into User.
91 * This will be done again after DNS resolution. -- w00t
95 Instance->local_users.push_back(New);
97 if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
99 Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
100 User::QuitUser(Instance, New,"No more connections allowed");
106 * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
107 * its a pretty big but for the moment valid assumption:
108 * file descriptors are handed out starting at 0, and are recycled as theyre freed.
109 * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
110 * irc server at once (or the irc server otherwise initiating this many connections, files etc)
111 * which for the time being is a physical impossibility (even the largest networks dont have more
112 * than about 10,000 users on ONE server!)
115 if ((unsigned int)socket >= MAX_DESCRIPTORS)
117 User::QuitUser(Instance, New, "Server is full");
122 * even with bancache, we still have to keep User::exempt current.
123 * besides that, if we get a positive bancache hit, we still won't fuck
124 * them over if they are exempt. -- w00t
126 New->exempt = (Instance->XLines->MatchesLine("E",New) != NULL);
128 if (BanCacheHit *b = Instance->BanCache->GetHit(New->GetIPString()))
130 if (!b->Type.empty() && !New->exempt)
133 Instance->Log(DEBUG, std::string("BanCache: Positive hit for ") + New->GetIPString());
134 if (*Instance->Config->MoronBanner)
135 New->WriteServ("NOTICE %s :*** %s", New->nick, Instance->Config->MoronBanner);
136 User::QuitUser(Instance, New, b->Reason);
141 Instance->Log(DEBUG, std::string("BanCache: Negative hit for ") + New->GetIPString());
148 XLine* r = Instance->XLines->MatchesLine("Z",New);
160 if (!Instance->SE->AddFd(New))
162 Instance->Log(DEBUG,"Internal error on new connection");
163 User::QuitUser(Instance, New, "Internal error handling connection");
167 /* NOTE: even if dns lookups are *off*, we still need to display this.
168 * BOPM and other stuff requires it.
170 New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
172 if (Instance->Config->NoUserDns)
174 New->dns_done = true;
178 New->StartDNSLookup();
182 void UserManager::AddLocalClone(User *user)
184 clonemap::iterator x = local_clones.find(user->GetIPString());
185 if (x != local_clones.end())
188 local_clones[user->GetIPString()] = 1;
191 void UserManager::AddGlobalClone(User *user)
193 clonemap::iterator y = global_clones.find(user->GetIPString());
194 if (y != global_clones.end())
197 global_clones[user->GetIPString()] = 1;
200 void UserManager::RemoveCloneCounts(User *user)
202 clonemap::iterator x = local_clones.find(user->GetIPString());
203 if (x != local_clones.end())
208 local_clones.erase(x);
212 clonemap::iterator y = global_clones.find(user->GetIPString());
213 if (y != global_clones.end())
218 global_clones.erase(y);
223 unsigned long UserManager::GlobalCloneCount(User *user)
225 clonemap::iterator x = global_clones.find(user->GetIPString());
226 if (x != global_clones.end())
232 unsigned long UserManager::LocalCloneCount(User *user)
234 clonemap::iterator x = local_clones.find(user->GetIPString());
235 if (x != local_clones.end())