]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/users.cpp
39a71719063dafbeca1d20e6456117cfeeef201b
[user/henk/code/inspircd.git] / src / users.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2006-2009 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2006-2007, 2009 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2008 John Brooks <john.brooks@dereferenced.net>
8  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
9  *   Copyright (C) 2008 Oliver Lupton <oliverlupton@gmail.com>
10  *   Copyright (C) 2003-2008 Craig Edwards <craigedwards@brainbox.cc>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27 #include <stdarg.h>
28 #include "socketengine.h"
29 #include "xline.h"
30 #include "bancache.h"
31
32 already_sent_t LocalUser::already_sent_id = 0;
33
34 bool User::IsNoticeMaskSet(unsigned char sm)
35 {
36         if (!isalpha(sm))
37                 return false;
38         return (snomasks[sm-65]);
39 }
40
41 bool User::IsModeSet(unsigned char m)
42 {
43         if (!isalpha(m))
44                 return false;
45         return (modes[m-65]);
46 }
47
48 const char* User::FormatModes(bool showparameters)
49 {
50         static std::string data;
51         std::string params;
52         data.clear();
53
54         for (unsigned char n = 0; n < 64; n++)
55         {
56                 if (modes[n])
57                 {
58                         data.push_back(n + 65);
59                         ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
60                         if (showparameters && mh && mh->GetNumParams(true))
61                         {
62                                 std::string p = mh->GetUserParameter(this);
63                                 if (p.length())
64                                         params.append(" ").append(p);
65                         }
66                 }
67         }
68         data += params;
69         return data.c_str();
70 }
71
72 User::User(const std::string &uid, const std::string& sid, int type)
73         : uuid(uid), server(sid), usertype(type)
74 {
75         age = ServerInstance->Time();
76         signon = 0;
77         registered = 0;
78         quietquit = quitting = false;
79         client_sa.sa.sa_family = AF_UNSPEC;
80
81         ServerInstance->Logs->Log("USERS", LOG_DEBUG, "New UUID for user: %s", uuid.c_str());
82
83         if (!ServerInstance->Users->uuidlist->insert(std::make_pair(uuid, this)).second)
84                 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
85 }
86
87 LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* servaddr)
88         : User(ServerInstance->UIDGen.GetUID(), ServerInstance->Config->ServerName, USERTYPE_LOCAL), eh(this),
89         localuseriter(ServerInstance->Users->local_users.end()),
90         bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0),
91         already_sent(0)
92 {
93         exempt = quitting_sendq = false;
94         idle_lastmsg = 0;
95         ident = "unknown";
96         lastping = 0;
97         eh.SetFd(myfd);
98         memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs));
99         memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs));
100         dhost = host = GetIPString();
101 }
102
103 User::~User()
104 {
105         if (ServerInstance->Users->uuidlist->find(uuid) != ServerInstance->Users->uuidlist->end())
106                 ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "User destructor for %s called without cull", uuid.c_str());
107 }
108
109 const std::string& User::MakeHost()
110 {
111         if (!this->cached_makehost.empty())
112                 return this->cached_makehost;
113
114         // XXX: Is there really a need to cache this?
115         this->cached_makehost = ident + "@" + host;
116         return this->cached_makehost;
117 }
118
119 const std::string& User::MakeHostIP()
120 {
121         if (!this->cached_hostip.empty())
122                 return this->cached_hostip;
123
124         // XXX: Is there really a need to cache this?
125         this->cached_hostip = ident + "@" + this->GetIPString();
126         return this->cached_hostip;
127 }
128
129 const std::string& User::GetFullHost()
130 {
131         if (!this->cached_fullhost.empty())
132                 return this->cached_fullhost;
133
134         // XXX: Is there really a need to cache this?
135         this->cached_fullhost = nick + "!" + ident + "@" + dhost;
136         return this->cached_fullhost;
137 }
138
139 const std::string& User::GetFullRealHost()
140 {
141         if (!this->cached_fullrealhost.empty())
142                 return this->cached_fullrealhost;
143
144         // XXX: Is there really a need to cache this?
145         this->cached_fullrealhost = nick + "!" + ident + "@" + host;
146         return this->cached_fullrealhost;
147 }
148
149 InviteList& LocalUser::GetInviteList()
150 {
151         RemoveExpiredInvites();
152         return invites;
153 }
154
155 bool LocalUser::RemoveInvite(Channel* chan)
156 {
157         Invitation* inv = Invitation::Find(chan, this);
158         if (inv)
159         {
160                 inv->cull();
161                 delete inv;
162                 return true;
163         }
164         return false;
165 }
166
167 void LocalUser::RemoveExpiredInvites()
168 {
169         Invitation::Find(NULL, this);
170 }
171
172 bool User::HasModePermission(unsigned char, ModeType)
173 {
174         return true;
175 }
176
177 bool LocalUser::HasModePermission(unsigned char mode, ModeType type)
178 {
179         if (!this->IsOper())
180                 return false;
181
182         if (mode < 'A' || mode > ('A' + 64)) return false;
183
184         return ((type == MODETYPE_USER ? oper->AllowedUserModes : oper->AllowedChanModes))[(mode - 'A')];
185
186 }
187 /*
188  * users on remote servers can completely bypass all permissions based checks.
189  * This prevents desyncs when one server has different type/class tags to another.
190  * That having been said, this does open things up to the possibility of source changes
191  * allowing remote kills, etc - but if they have access to the src, they most likely have
192  * access to the conf - so it's an end to a means either way.
193  */
194 bool User::HasPermission(const std::string&)
195 {
196         return true;
197 }
198
199 bool LocalUser::HasPermission(const std::string &command)
200 {
201         // are they even an oper at all?
202         if (!this->IsOper())
203         {
204                 return false;
205         }
206
207         if (oper->AllowedOperCommands.find(command) != oper->AllowedOperCommands.end())
208                 return true;
209         else if (oper->AllowedOperCommands.find("*") != oper->AllowedOperCommands.end())
210                 return true;
211
212         return false;
213 }
214
215 bool User::HasPrivPermission(const std::string &privstr, bool noisy)
216 {
217         return true;
218 }
219
220 bool LocalUser::HasPrivPermission(const std::string &privstr, bool noisy)
221 {
222         if (!this->IsOper())
223         {
224                 if (noisy)
225                         this->WriteNotice("You are not an oper");
226                 return false;
227         }
228
229         if (oper->AllowedPrivs.find(privstr) != oper->AllowedPrivs.end())
230         {
231                 return true;
232         }
233         else if (oper->AllowedPrivs.find("*") != oper->AllowedPrivs.end())
234         {
235                 return true;
236         }
237
238         if (noisy)
239                 this->WriteNotice("Oper type " + oper->name + " does not have access to priv " + privstr);
240
241         return false;
242 }
243
244 void UserIOHandler::OnDataReady()
245 {
246         if (user->quitting)
247                 return;
248
249         if (recvq.length() > user->MyClass->GetRecvqMax() && !user->HasPrivPermission("users/flood/increased-buffers"))
250         {
251                 ServerInstance->Users->QuitUser(user, "RecvQ exceeded");
252                 ServerInstance->SNO->WriteToSnoMask('a', "User %s RecvQ of %lu exceeds connect class maximum of %lu",
253                         user->nick.c_str(), (unsigned long)recvq.length(), user->MyClass->GetRecvqMax());
254                 return;
255         }
256         unsigned long sendqmax = ULONG_MAX;
257         if (!user->HasPrivPermission("users/flood/increased-buffers"))
258                 sendqmax = user->MyClass->GetSendqSoftMax();
259         unsigned long penaltymax = ULONG_MAX;
260         if (!user->HasPrivPermission("users/flood/no-fakelag"))
261                 penaltymax = user->MyClass->GetPenaltyThreshold() * 1000;
262
263         while (user->CommandFloodPenalty < penaltymax && getSendQSize() < sendqmax)
264         {
265                 std::string line;
266                 line.reserve(ServerInstance->Config->Limits.MaxLine);
267                 std::string::size_type qpos = 0;
268                 while (qpos < recvq.length())
269                 {
270                         char c = recvq[qpos++];
271                         switch (c)
272                         {
273                         case '\0':
274                                 c = ' ';
275                                 break;
276                         case '\r':
277                                 continue;
278                         case '\n':
279                                 goto eol_found;
280                         }
281                         if (line.length() < ServerInstance->Config->Limits.MaxLine - 2)
282                                 line.push_back(c);
283                 }
284                 // if we got here, the recvq ran out before we found a newline
285                 return;
286 eol_found:
287                 // just found a newline. Terminate the string, and pull it out of recvq
288                 recvq = recvq.substr(qpos);
289
290                 // TODO should this be moved to when it was inserted in recvq?
291                 ServerInstance->stats->statsRecv += qpos;
292                 user->bytes_in += qpos;
293                 user->cmds_in++;
294
295                 ServerInstance->Parser->ProcessBuffer(line, user);
296                 if (user->quitting)
297                         return;
298         }
299         if (user->CommandFloodPenalty >= penaltymax && !user->MyClass->fakelag)
300                 ServerInstance->Users->QuitUser(user, "Excess Flood");
301 }
302
303 void UserIOHandler::AddWriteBuf(const std::string &data)
304 {
305         if (user->quitting_sendq)
306                 return;
307         if (!user->quitting && getSendQSize() + data.length() > user->MyClass->GetSendqHardMax() &&
308                 !user->HasPrivPermission("users/flood/increased-buffers"))
309         {
310                 user->quitting_sendq = true;
311                 ServerInstance->GlobalCulls.AddSQItem(user);
312                 return;
313         }
314
315         // We still want to append data to the sendq of a quitting user,
316         // e.g. their ERROR message that says 'closing link'
317
318         WriteData(data);
319 }
320
321 void UserIOHandler::OnError(BufferedSocketError)
322 {
323         ServerInstance->Users->QuitUser(user, getError());
324 }
325
326 CullResult User::cull()
327 {
328         if (!quitting)
329                 ServerInstance->Users->QuitUser(this, "Culled without QuitUser");
330         PurgeEmptyChannels();
331
332         if (client_sa.sa.sa_family != AF_UNSPEC)
333                 ServerInstance->Users->RemoveCloneCounts(this);
334
335         return Extensible::cull();
336 }
337
338 CullResult LocalUser::cull()
339 {
340         // The iterator is initialized to local_users.end() in the constructor. It is
341         // overwritten in UserManager::AddUser() with the real iterator so this check
342         // is only a precaution currently.
343         if (localuseriter != ServerInstance->Users->local_users.end())
344         {
345                 ServerInstance->Users->local_count--;
346                 ServerInstance->Users->local_users.erase(localuseriter);
347         }
348         else
349                 ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: LocalUserIter does not point to a valid entry for " + this->nick);
350
351         ClearInvites();
352         eh.cull();
353         return User::cull();
354 }
355
356 CullResult FakeUser::cull()
357 {
358         // Fake users don't quit, they just get culled.
359         quitting = true;
360         // Fake users are not inserted into UserManager::clientlist, they're only in the uuidlist
361         ServerInstance->Users->uuidlist->erase(uuid);
362         return User::cull();
363 }
364
365 void User::Oper(OperInfo* info)
366 {
367         ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER);
368         if (this->IsModeSet(opermh))
369                 this->UnOper();
370
371         this->SetMode(opermh, true);
372         this->oper = info;
373         this->WriteServ("MODE %s :+o", this->nick.c_str());
374         FOREACH_MOD(OnOper, (this, info->name));
375
376         std::string opername;
377         if (info->oper_block)
378                 opername = info->oper_block->getString("name");
379
380         if (IS_LOCAL(this))
381         {
382                 LocalUser* l = IS_LOCAL(this);
383                 std::string vhost = oper->getConfig("vhost");
384                 if (!vhost.empty())
385                         l->ChangeDisplayedHost(vhost.c_str());
386                 std::string opClass = oper->getConfig("class");
387                 if (!opClass.empty())
388                         l->SetClass(opClass);
389         }
390
391         ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')",
392                 nick.c_str(), ident.c_str(), host.c_str(), oper->name.c_str(), opername.c_str());
393         this->WriteNumeric(RPL_YOUAREOPER, ":You are now %s %s", strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->name.c_str());
394
395         ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->name.c_str());
396         ServerInstance->Users->all_opers.push_back(this);
397
398         // Expand permissions from config for faster lookup
399         if (IS_LOCAL(this))
400                 oper->init();
401
402         FOREACH_MOD(OnPostOper, (this, oper->name, opername));
403 }
404
405 void OperInfo::init()
406 {
407         AllowedOperCommands.clear();
408         AllowedPrivs.clear();
409         AllowedUserModes.reset();
410         AllowedChanModes.reset();
411         AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
412
413         for(std::vector<reference<ConfigTag> >::iterator iter = class_blocks.begin(); iter != class_blocks.end(); ++iter)
414         {
415                 ConfigTag* tag = *iter;
416                 std::string mycmd, mypriv;
417                 /* Process commands */
418                 irc::spacesepstream CommandList(tag->getString("commands"));
419                 while (CommandList.GetToken(mycmd))
420                 {
421                         AllowedOperCommands.insert(mycmd);
422                 }
423
424                 irc::spacesepstream PrivList(tag->getString("privs"));
425                 while (PrivList.GetToken(mypriv))
426                 {
427                         AllowedPrivs.insert(mypriv);
428                 }
429
430                 std::string modes = tag->getString("usermodes");
431                 for (std::string::const_iterator c = modes.begin(); c != modes.end(); ++c)
432                 {
433                         if (*c == '*')
434                         {
435                                 this->AllowedUserModes.set();
436                         }
437                         else if (*c >= 'A' && *c < 'z')
438                         {
439                                 this->AllowedUserModes[*c - 'A'] = true;
440                         }
441                 }
442
443                 modes = tag->getString("chanmodes");
444                 for (std::string::const_iterator c = modes.begin(); c != modes.end(); ++c)
445                 {
446                         if (*c == '*')
447                         {
448                                 this->AllowedChanModes.set();
449                         }
450                         else if (*c >= 'A' && *c < 'z')
451                         {
452                                 this->AllowedChanModes[*c - 'A'] = true;
453                         }
454                 }
455         }
456 }
457
458 void User::UnOper()
459 {
460         if (!this->IsOper())
461                 return;
462
463         /*
464          * unset their oper type (what IS_OPER checks).
465          * note, order is important - this must come before modes as -o attempts
466          * to call UnOper. -- w00t
467          */
468         oper = NULL;
469
470
471         /* Remove all oper only modes from the user when the deoper - Bug #466*/
472         std::string moderemove("-");
473
474         for (unsigned char letter = 'A'; letter <= 'z'; letter++)
475         {
476                 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
477                 if (mh && mh->NeedsOper())
478                         moderemove += letter;
479         }
480
481
482         std::vector<std::string> parameters;
483         parameters.push_back(this->nick);
484         parameters.push_back(moderemove);
485
486         ServerInstance->Modes->Process(parameters, this);
487
488         /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
489         ServerInstance->Users->all_opers.remove(this);
490
491         ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER);
492         this->SetMode(opermh, false);
493 }
494
495 /*
496  * Check class restrictions
497  */
498 void LocalUser::CheckClass(bool clone_count)
499 {
500         ConnectClass* a = this->MyClass;
501
502         if (!a)
503         {
504                 ServerInstance->Users->QuitUser(this, "Access denied by configuration");
505                 return;
506         }
507         else if (a->type == CC_DENY)
508         {
509                 ServerInstance->Users->QuitUser(this, a->config->getString("reason", "Unauthorised connection"));
510                 return;
511         }
512         else if (clone_count)
513         {
514                 if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
515                 {
516                         ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
517                         if (a->maxconnwarn)
518                                 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString().c_str());
519                         return;
520                 }
521                 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
522                 {
523                         ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
524                         if (a->maxconnwarn)
525                                 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString().c_str());
526                         return;
527                 }
528         }
529
530         this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
531 }
532
533 bool LocalUser::CheckLines(bool doZline)
534 {
535         const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
536
537         if (!this->exempt)
538         {
539                 for (int n = 0; check[n]; ++n)
540                 {
541                         XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
542
543                         if (r)
544                         {
545                                 r->Apply(this);
546                                 return true;
547                         }
548                 }
549         }
550
551         return false;
552 }
553
554 void LocalUser::FullConnect()
555 {
556         ServerInstance->stats->statsConnects++;
557         this->idle_lastmsg = ServerInstance->Time();
558
559         /*
560          * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
561          * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
562          * may put the user into a totally seperate class with different restrictions! so we *must* check again.
563          * Don't remove this! -- w00t
564          */
565         MyClass = NULL;
566         SetClass();
567         CheckClass();
568         CheckLines();
569
570         if (quitting)
571                 return;
572
573         this->WriteNumeric(RPL_WELCOME, ":Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), GetFullRealHost().c_str());
574         this->WriteNumeric(RPL_YOURHOSTIS, ":Your host is %s, running version %s", ServerInstance->Config->ServerName.c_str(), BRANCH);
575         this->WriteNumeric(RPL_SERVERCREATED, ":This server was created %s %s", __TIME__, __DATE__);
576
577         const std::string& modelist = ServerInstance->Modes->GetModeListFor004Numeric();
578         this->WriteNumeric(RPL_SERVERVERSION, "%s %s %s", ServerInstance->Config->ServerName.c_str(), BRANCH, modelist.c_str());
579
580         ServerInstance->ISupport.SendTo(this);
581         this->WriteNumeric(RPL_YOURUUID, "%s :your unique ID", this->uuid.c_str());
582
583         /* Now registered */
584         if (ServerInstance->Users->unregistered_count)
585                 ServerInstance->Users->unregistered_count--;
586
587         /* Trigger MOTD and LUSERS output, give modules a chance too */
588         ModResult MOD_RESULT;
589         std::string command("LUSERS");
590         std::vector<std::string> parameters;
591         FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
592         if (!MOD_RESULT)
593                 ServerInstance->Parser->CallHandler(command, parameters, this);
594
595         MOD_RESULT = MOD_RES_PASSTHRU;
596         command = "MOTD";
597         FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
598         if (!MOD_RESULT)
599                 ServerInstance->Parser->CallHandler(command, parameters, this);
600
601         if (ServerInstance->Config->RawLog)
602                 WriteServ("PRIVMSG %s :*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.", nick.c_str());
603
604         /*
605          * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
606          * for a user that doesn't exist yet.
607          */
608         FOREACH_MOD(OnUserConnect, (this));
609
610         this->registered = REG_ALL;
611
612         FOREACH_MOD(OnPostConnect, (this));
613
614         ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d (class %s): %s (%s) [%s]",
615                 this->GetServerPort(), this->MyClass->name.c_str(), GetFullRealHost().c_str(), this->GetIPString().c_str(), this->fullname.c_str());
616         ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCache: Adding NEGATIVE hit for " + this->GetIPString());
617         ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
618         // reset the flood penalty (which could have been raised due to things like auto +x)
619         CommandFloodPenalty = 0;
620 }
621
622 void User::InvalidateCache()
623 {
624         /* Invalidate cache */
625         cached_fullhost.clear();
626         cached_hostip.clear();
627         cached_makehost.clear();
628         cached_fullrealhost.clear();
629 }
630
631 bool User::ChangeNick(const std::string& newnick, bool force)
632 {
633         if (quitting)
634         {
635                 ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: Attempted to change nick of a quitting user: " + this->nick);
636                 return false;
637         }
638
639         if (!force)
640         {
641                 ModResult MOD_RESULT;
642                 FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (this, newnick));
643
644                 if (MOD_RESULT == MOD_RES_DENY)
645                 {
646                         ServerInstance->stats->statsCollisions++;
647                         return false;
648                 }
649         }
650
651         if (assign(newnick) == assign(nick))
652         {
653                 // case change, don't need to check Q:lines and such
654                 // and, if it's identical including case, we can leave right now
655                 if (newnick == nick)
656                         return true;
657         }
658         else
659         {
660                 /*
661                  * Don't check Q:Lines if it's a server-enforced change, just on the off-chance some fucking *moron*
662                  * tries to Q:Line SIDs, also, this means we just get our way period, as it really should be.
663                  * Thanks Kein for finding this. -- w00t
664                  *
665                  * Also don't check Q:Lines for remote nickchanges, they should have our Q:Lines anyway to enforce themselves.
666                  *              -- w00t
667                  */
668                 if (IS_LOCAL(this) && !force)
669                 {
670                         XLine* mq = ServerInstance->XLines->MatchesLine("Q",newnick);
671                         if (mq)
672                         {
673                                 if (this->registered == REG_ALL)
674                                 {
675                                         ServerInstance->SNO->WriteGlobalSno('a', "Q-Lined nickname %s from %s: %s",
676                                                 newnick.c_str(), GetFullRealHost().c_str(), mq->reason.c_str());
677                                 }
678                                 this->WriteNumeric(ERR_ERRONEUSNICKNAME, "%s :Invalid nickname: %s", newnick.c_str(), mq->reason.c_str());
679                                 return false;
680                         }
681
682                         if (ServerInstance->Config->RestrictBannedUsers)
683                         {
684                                 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
685                                 {
686                                         Channel *chan = *i;
687                                         if (chan->GetPrefixValue(this) < VOICE_VALUE && chan->IsBanned(this))
688                                         {
689                                                 this->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel (you're banned)", chan->name.c_str());
690                                                 return false;
691                                         }
692                                 }
693                         }
694                 }
695
696                 /*
697                  * Uh oh.. if the nickname is in use, and it's not in use by the person using it (doh) --
698                  * then we have a potential collide. Check whether someone else is camping on the nick
699                  * (i.e. connect -> send NICK, don't send USER.) If they are camping, force-change the
700                  * camper to their UID, and allow the incoming nick change.
701                  *
702                  * If the guy using the nick is already using it, tell the incoming nick change to gtfo,
703                  * because the nick is already (rightfully) in use. -- w00t
704                  */
705                 User* InUse = ServerInstance->FindNickOnly(newnick);
706                 if (InUse && (InUse != this))
707                 {
708                         if (InUse->registered != REG_ALL)
709                         {
710                                 /* force the camper to their UUID, and ask them to re-send a NICK. */
711                                 InUse->WriteTo(InUse, "NICK %s", InUse->uuid.c_str());
712                                 InUse->WriteNumeric(ERR_NICKNAMEINUSE, "%s :Nickname overruled.", InUse->nick.c_str());
713
714                                 ServerInstance->Users->clientlist->erase(InUse->nick);
715                                 (*(ServerInstance->Users->clientlist))[InUse->uuid] = InUse;
716
717                                 InUse->nick = InUse->uuid;
718                                 InUse->InvalidateCache();
719                                 InUse->registered &= ~REG_NICK;
720                         }
721                         else
722                         {
723                                 /* No camping, tell the incoming user  to stop trying to change nick ;p */
724                                 this->WriteNumeric(ERR_NICKNAMEINUSE, "%s :Nickname is already in use.", newnick.c_str());
725                                 return false;
726                         }
727                 }
728         }
729
730         if (this->registered == REG_ALL)
731                 this->WriteCommon("NICK %s",newnick.c_str());
732         std::string oldnick = nick;
733         nick = newnick;
734
735         InvalidateCache();
736         ServerInstance->Users->clientlist->erase(oldnick);
737         (*(ServerInstance->Users->clientlist))[newnick] = this;
738
739         if (registered == REG_ALL)
740                 FOREACH_MOD(OnUserPostNick, (this,oldnick));
741
742         return true;
743 }
744
745 int LocalUser::GetServerPort()
746 {
747         switch (this->server_sa.sa.sa_family)
748         {
749                 case AF_INET6:
750                         return htons(this->server_sa.in6.sin6_port);
751                 case AF_INET:
752                         return htons(this->server_sa.in4.sin_port);
753         }
754         return 0;
755 }
756
757 const std::string& User::GetIPString()
758 {
759         int port;
760         if (cachedip.empty())
761         {
762                 irc::sockets::satoap(client_sa, cachedip, port);
763                 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
764                 if (cachedip[0] == ':')
765                         cachedip.insert(0,1,'0');
766         }
767
768         return cachedip;
769 }
770
771 irc::sockets::cidr_mask User::GetCIDRMask()
772 {
773         int range = 0;
774         switch (client_sa.sa.sa_family)
775         {
776                 case AF_INET6:
777                         range = ServerInstance->Config->c_ipv6_range;
778                         break;
779                 case AF_INET:
780                         range = ServerInstance->Config->c_ipv4_range;
781                         break;
782         }
783         return irc::sockets::cidr_mask(client_sa, range);
784 }
785
786 bool User::SetClientIP(const char* sip, bool recheck_eline)
787 {
788         cachedip.clear();
789         cached_hostip.clear();
790         return irc::sockets::aptosa(sip, 0, client_sa);
791 }
792
793 void User::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline)
794 {
795         cachedip.clear();
796         cached_hostip.clear();
797         memcpy(&client_sa, &sa, sizeof(irc::sockets::sockaddrs));
798 }
799
800 bool LocalUser::SetClientIP(const char* sip, bool recheck_eline)
801 {
802         irc::sockets::sockaddrs sa;
803         if (!irc::sockets::aptosa(sip, 0, sa))
804                 // Invalid
805                 return false;
806
807         LocalUser::SetClientIP(sa, recheck_eline);
808         return true;
809 }
810
811 void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline)
812 {
813         if (sa != client_sa)
814         {
815                 User::SetClientIP(sa);
816                 if (recheck_eline)
817                         this->exempt = (ServerInstance->XLines->MatchesLine("E", this) != NULL);
818
819                 FOREACH_MOD(OnSetUserIP, (this));
820         }
821 }
822
823 static std::string wide_newline("\r\n");
824
825 void User::Write(const std::string& text)
826 {
827 }
828
829 void User::Write(const char *text, ...)
830 {
831 }
832
833 void LocalUser::Write(const std::string& text)
834 {
835         if (!ServerInstance->SE->BoundsCheckFd(&eh))
836                 return;
837
838         if (text.length() > ServerInstance->Config->Limits.MaxLine - 2)
839         {
840                 // this should happen rarely or never. Crop the string at 512 and try again.
841                 std::string try_again = text.substr(0, ServerInstance->Config->Limits.MaxLine - 2);
842                 Write(try_again);
843                 return;
844         }
845
846         ServerInstance->Logs->Log("USEROUTPUT", LOG_RAWIO, "C[%s] O %s", uuid.c_str(), text.c_str());
847
848         eh.AddWriteBuf(text);
849         eh.AddWriteBuf(wide_newline);
850
851         ServerInstance->stats->statsSent += text.length() + 2;
852         this->bytes_out += text.length() + 2;
853         this->cmds_out++;
854 }
855
856 /** Write()
857  */
858 void LocalUser::Write(const char *text, ...)
859 {
860         std::string textbuffer;
861         VAFORMAT(textbuffer, text, text);
862         this->Write(textbuffer);
863 }
864
865 void User::WriteServ(const std::string& text)
866 {
867         this->Write(":%s %s",ServerInstance->Config->ServerName.c_str(),text.c_str());
868 }
869
870 /** WriteServ()
871  *  Same as Write(), except `text' is prefixed with `:server.name '.
872  */
873 void User::WriteServ(const char* text, ...)
874 {
875         std::string textbuffer;
876         VAFORMAT(textbuffer, text, text);
877         this->WriteServ(textbuffer);
878 }
879
880 void User::WriteNotice(const std::string& text)
881 {
882         this->WriteServ("NOTICE " + (this->registered == REG_ALL ? this->nick : "*") + " :" + text);
883 }
884
885 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
886 {
887         std::string textbuffer;
888         VAFORMAT(textbuffer, text, text);
889         this->WriteNumeric(numeric, textbuffer);
890 }
891
892 void User::WriteNumeric(unsigned int numeric, const std::string &text)
893 {
894         ModResult MOD_RESULT;
895
896         FIRST_MOD_RESULT(OnNumeric, MOD_RESULT, (this, numeric, text));
897
898         if (MOD_RESULT == MOD_RES_DENY)
899                 return;
900         
901         const std::string message = InspIRCd::Format(":%s %03u %s %s", ServerInstance->Config->ServerName.c_str(),
902                 numeric, !this->nick.empty() ? this->nick.c_str() : "*", text.c_str());
903         this->Write(message);
904 }
905
906 void User::WriteFrom(User *user, const std::string &text)
907 {
908         const std::string message = ":" + user->GetFullHost() + " " + text;
909         this->Write(message);
910 }
911
912
913 /* write text from an originating user to originating user */
914
915 void User::WriteFrom(User *user, const char* text, ...)
916 {
917         std::string textbuffer;
918         VAFORMAT(textbuffer, text, text);
919         this->WriteFrom(user, textbuffer);
920 }
921
922
923 /* write text to an destination user from a source user (e.g. user privmsg) */
924
925 void User::WriteTo(User *dest, const char *data, ...)
926 {
927         std::string textbuffer;
928         VAFORMAT(textbuffer, data, data);
929         this->WriteTo(dest, textbuffer);
930 }
931
932 void User::WriteTo(User *dest, const std::string &data)
933 {
934         dest->WriteFrom(this, data);
935 }
936
937 void User::WriteCommon(const char* text, ...)
938 {
939         if (this->registered != REG_ALL || quitting)
940                 return;
941
942         std::string textbuffer;
943         VAFORMAT(textbuffer, text, text);
944         textbuffer = ":" + this->GetFullHost() + " " + textbuffer;
945         this->WriteCommonRaw(textbuffer, true);
946 }
947
948 void User::WriteCommonExcept(const char* text, ...)
949 {
950         if (this->registered != REG_ALL || quitting)
951                 return;
952
953         std::string textbuffer;
954         VAFORMAT(textbuffer, text, text);
955         textbuffer = ":" + this->GetFullHost() + " " + textbuffer;
956         this->WriteCommonRaw(textbuffer, false);
957 }
958
959 void User::WriteCommonRaw(const std::string &line, bool include_self)
960 {
961         if (this->registered != REG_ALL || quitting)
962                 return;
963
964         LocalUser::already_sent_id++;
965
966         UserChanList include_c(chans);
967         std::map<User*,bool> exceptions;
968
969         exceptions[this] = include_self;
970
971         FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions));
972
973         for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
974         {
975                 LocalUser* u = IS_LOCAL(i->first);
976                 if (u && !u->quitting)
977                 {
978                         u->already_sent = LocalUser::already_sent_id;
979                         if (i->second)
980                                 u->Write(line);
981                 }
982         }
983         for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
984         {
985                 Channel* c = *v;
986                 const UserMembList* ulist = c->GetUsers();
987                 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
988                 {
989                         LocalUser* u = IS_LOCAL(i->first);
990                         if (u && !u->quitting && u->already_sent != LocalUser::already_sent_id)
991                         {
992                                 u->already_sent = LocalUser::already_sent_id;
993                                 u->Write(line);
994                         }
995                 }
996         }
997 }
998
999 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1000 {
1001         if (this->registered != REG_ALL)
1002                 return;
1003
1004         already_sent_t uniq_id = ++LocalUser::already_sent_id;
1005
1006         const std::string normalMessage = ":" + this->GetFullHost() + " QUIT :" + normal_text;
1007         const std::string operMessage = ":" + this->GetFullHost() + " QUIT :" + oper_text;
1008
1009         UserChanList include_c(chans);
1010         std::map<User*,bool> exceptions;
1011
1012         FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions));
1013
1014         for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
1015         {
1016                 LocalUser* u = IS_LOCAL(i->first);
1017                 if (u && !u->quitting)
1018                 {
1019                         u->already_sent = uniq_id;
1020                         if (i->second)
1021                                 u->Write(u->IsOper() ? operMessage : normalMessage);
1022                 }
1023         }
1024         for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
1025         {
1026                 const UserMembList* ulist = (*v)->GetUsers();
1027                 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1028                 {
1029                         LocalUser* u = IS_LOCAL(i->first);
1030                         if (u && !u->quitting && (u->already_sent != uniq_id))
1031                         {
1032                                 u->already_sent = uniq_id;
1033                                 u->Write(u->IsOper() ? operMessage : normalMessage);
1034                         }
1035                 }
1036         }
1037 }
1038
1039 void LocalUser::SendText(const std::string& line)
1040 {
1041         Write(line);
1042 }
1043
1044 void RemoteUser::SendText(const std::string& line)
1045 {
1046         ServerInstance->PI->PushToClient(this, line);
1047 }
1048
1049 void FakeUser::SendText(const std::string& line)
1050 {
1051 }
1052
1053 void User::SendText(const char *text, ...)
1054 {
1055         std::string line;
1056         VAFORMAT(line, text, text);
1057         SendText(line);
1058 }
1059
1060 void User::SendText(const std::string& linePrefix, std::stringstream& textStream)
1061 {
1062         std::string line;
1063         std::string word;
1064         while (textStream >> word)
1065         {
1066                 size_t lineLength = linePrefix.length() + line.length() + word.length() + 3; // "\s\n\r"
1067                 if (lineLength > ServerInstance->Config->Limits.MaxLine)
1068                 {
1069                         SendText(linePrefix + line);
1070                         line.clear();
1071                 }
1072                 line += " " + word;
1073         }
1074         SendText(linePrefix + line);
1075 }
1076
1077 /* return 0 or 1 depending if users u and u2 share one or more common channels
1078  * (used by QUIT, NICK etc which arent channel specific notices)
1079  *
1080  * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1081  * the first users channels then the second users channels within the outer loop,
1082  * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1083  * all possible iterations). However this new function instead checks against the
1084  * channel's userlist in the inner loop which is a std::map<User*,User*>
1085  * and saves us time as we already know what pointer value we are after.
1086  * Don't quote me on the maths as i am not a mathematician or computer scientist,
1087  * but i believe this algorithm is now x+(log y) maximum iterations instead.
1088  */
1089 bool User::SharesChannelWith(User *other)
1090 {
1091         if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1092                 return false;
1093
1094         /* Outer loop */
1095         for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1096         {
1097                 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1098                  * by replacing it with a map::find which *should* be more efficient
1099                  */
1100                 if ((*i)->HasUser(other))
1101                         return true;
1102         }
1103         return false;
1104 }
1105
1106 bool User::ChangeName(const std::string& gecos)
1107 {
1108         if (!this->fullname.compare(gecos))
1109                 return true;
1110
1111         if (IS_LOCAL(this))
1112         {
1113                 ModResult MOD_RESULT;
1114                 FIRST_MOD_RESULT(OnChangeLocalUserGECOS, MOD_RESULT, (IS_LOCAL(this),gecos));
1115                 if (MOD_RESULT == MOD_RES_DENY)
1116                         return false;
1117                 FOREACH_MOD(OnChangeName, (this,gecos));
1118         }
1119         this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1120
1121         return true;
1122 }
1123
1124 bool User::ChangeDisplayedHost(const std::string& shost)
1125 {
1126         if (dhost == shost)
1127                 return true;
1128
1129         if (IS_LOCAL(this))
1130         {
1131                 ModResult MOD_RESULT;
1132                 FIRST_MOD_RESULT(OnChangeLocalUserHost, MOD_RESULT, (IS_LOCAL(this),shost));
1133                 if (MOD_RESULT == MOD_RES_DENY)
1134                         return false;
1135         }
1136
1137         FOREACH_MOD(OnChangeHost, (this,shost));
1138
1139         this->dhost.assign(shost, 0, 64);
1140         this->InvalidateCache();
1141
1142         if (IS_LOCAL(this))
1143                 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s :is now your displayed host", this->dhost.c_str());
1144
1145         return true;
1146 }
1147
1148 bool User::ChangeIdent(const std::string& newident)
1149 {
1150         if (this->ident == newident)
1151                 return true;
1152
1153         FOREACH_MOD(OnChangeIdent, (this,newident));
1154
1155         this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax);
1156         this->InvalidateCache();
1157
1158         return true;
1159 }
1160
1161 void User::SendAll(const char* command, const char* text, ...)
1162 {
1163         std::string textbuffer;
1164         VAFORMAT(textbuffer, text, text);
1165         const std::string message = ":" + this->GetFullHost() + " " + command + " $* :" + textbuffer;
1166
1167         for (LocalUserList::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1168         {
1169                 if ((*i)->registered == REG_ALL)
1170                         (*i)->Write(message);
1171         }
1172 }
1173
1174 /*
1175  * Sets a user's connection class.
1176  * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1177  * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1178  * then their ip will be taken as 'priority' anyway, so for example,
1179  * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1180  */
1181 void LocalUser::SetClass(const std::string &explicit_name)
1182 {
1183         ConnectClass *found = NULL;
1184
1185         ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1186
1187         if (!explicit_name.empty())
1188         {
1189                 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1190                 {
1191                         ConnectClass* c = *i;
1192
1193                         if (explicit_name == c->name)
1194                         {
1195                                 ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Explicitly set to %s", explicit_name.c_str());
1196                                 found = c;
1197                         }
1198                 }
1199         }
1200         else
1201         {
1202                 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1203                 {
1204                         ConnectClass* c = *i;
1205                         ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Checking %s", c->GetName().c_str());
1206
1207                         ModResult MOD_RESULT;
1208                         FIRST_MOD_RESULT(OnSetConnectClass, MOD_RESULT, (this,c));
1209                         if (MOD_RESULT == MOD_RES_DENY)
1210                                 continue;
1211                         if (MOD_RESULT == MOD_RES_ALLOW)
1212                         {
1213                                 ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Class forced by module to %s", c->GetName().c_str());
1214                                 found = c;
1215                                 break;
1216                         }
1217
1218                         if (c->type == CC_NAMED)
1219                                 continue;
1220
1221                         bool regdone = (registered != REG_NONE);
1222                         if (c->config->getBool("registered", regdone) != regdone)
1223                                 continue;
1224
1225                         /* check if host matches.. */
1226                         if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1227                             !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1228                         {
1229                                 ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "No host match (for %s)", c->GetHost().c_str());
1230                                 continue;
1231                         }
1232
1233                         /*
1234                          * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1235                          * because we should attempt to find another class if this one doesn't match us. -- w00t
1236                          */
1237                         if (c->limit && (c->GetReferenceCount() >= c->limit))
1238                         {
1239                                 ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1240                                 continue;
1241                         }
1242
1243                         /* if it requires a port ... */
1244                         int port = c->config->getInt("port");
1245                         if (port)
1246                         {
1247                                 ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Requires port (%d)", port);
1248
1249                                 /* and our port doesn't match, fail. */
1250                                 if (this->GetServerPort() != port)
1251                                         continue;
1252                         }
1253
1254                         if (regdone && !c->config->getString("password").empty())
1255                         {
1256                                 if (ServerInstance->PassCompare(this, c->config->getString("password"), password, c->config->getString("hash")))
1257                                 {
1258                                         ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Bad password, skipping");
1259                                         continue;
1260                                 }
1261                         }
1262
1263                         /* we stop at the first class that meets ALL critera. */
1264                         found = c;
1265                         break;
1266                 }
1267         }
1268
1269         /*
1270          * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1271          */
1272         if (found)
1273         {
1274                 MyClass = found;
1275         }
1276 }
1277
1278 void User::PurgeEmptyChannels()
1279 {
1280         // firstly decrement the count on each channel
1281         for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1282         {
1283                 Channel* c = *f;
1284                 c->DelUser(this);
1285         }
1286
1287         this->UnOper();
1288 }
1289
1290 const std::string& FakeUser::GetFullHost()
1291 {
1292         if (!ServerInstance->Config->HideWhoisServer.empty())
1293                 return ServerInstance->Config->HideWhoisServer;
1294         return server;
1295 }
1296
1297 const std::string& FakeUser::GetFullRealHost()
1298 {
1299         if (!ServerInstance->Config->HideWhoisServer.empty())
1300                 return ServerInstance->Config->HideWhoisServer;
1301         return server;
1302 }
1303
1304 ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask)
1305         : config(tag), type(t), fakelag(true), name("unnamed"), registration_timeout(0), host(mask),
1306         pingtime(0), softsendqmax(0), hardsendqmax(0), recvqmax(0),
1307         penaltythreshold(0), commandrate(0), maxlocal(0), maxglobal(0), maxconnwarn(true), maxchans(0),
1308         limit(0), resolvehostnames(true)
1309 {
1310 }
1311
1312 ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask, const ConnectClass& parent)
1313         : config(tag), type(t), fakelag(parent.fakelag), name("unnamed"),
1314         registration_timeout(parent.registration_timeout), host(mask), pingtime(parent.pingtime),
1315         softsendqmax(parent.softsendqmax), hardsendqmax(parent.hardsendqmax), recvqmax(parent.recvqmax),
1316         penaltythreshold(parent.penaltythreshold), commandrate(parent.commandrate),
1317         maxlocal(parent.maxlocal), maxglobal(parent.maxglobal), maxconnwarn(parent.maxconnwarn), maxchans(parent.maxchans),
1318         limit(parent.limit), resolvehostnames(parent.resolvehostnames)
1319 {
1320 }
1321
1322 void ConnectClass::Update(const ConnectClass* src)
1323 {
1324         config = src->config;
1325         type = src->type;
1326         fakelag = src->fakelag;
1327         name = src->name;
1328         registration_timeout = src->registration_timeout;
1329         host = src->host;
1330         pingtime = src->pingtime;
1331         softsendqmax = src->softsendqmax;
1332         hardsendqmax = src->hardsendqmax;
1333         recvqmax = src->recvqmax;
1334         penaltythreshold = src->penaltythreshold;
1335         commandrate = src->commandrate;
1336         maxlocal = src->maxlocal;
1337         maxglobal = src->maxglobal;
1338         maxconnwarn = src->maxconnwarn;
1339         maxchans = src->maxchans;
1340         limit = src->limit;
1341         resolvehostnames = src->resolvehostnames;
1342 }