]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/configreader.cpp
Remove the old TODO comment
[user/henk/code/inspircd.git] / src / configreader.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $Core */
15 /* $CopyInstall: conf/inspircd.quotes.example $(CONPATH) */
16 /* $CopyInstall: conf/inspircd.rules.example $(CONPATH) */
17 /* $CopyInstall: conf/inspircd.motd.example $(CONPATH) */
18 /* $CopyInstall: conf/inspircd.helpop-full.example $(CONPATH) */
19 /* $CopyInstall: conf/inspircd.helpop.example $(CONPATH) */
20 /* $CopyInstall: conf/inspircd.censor.example $(CONPATH) */
21 /* $CopyInstall: conf/inspircd.filter.example $(CONPATH) */
22 /* $CopyInstall: conf/inspircd.conf.example $(CONPATH) */
23 /* $CopyInstall: conf/modules.conf.example $(CONPATH) */
24
25 #include "inspircd.h"
26 #include <fstream>
27 #include "xline.h"
28 #include "exitcodes.h"
29 #include "commands/cmd_whowas.h"
30
31 std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
32
33 /* Needs forward declaration */
34 bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);
35 bool DoneELine(ServerConfig* conf, const char* tag);
36
37 ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
38 {
39         this->ClearStack();
40         *sid = *ServerName = *Network = *ServerDesc = *AdminName = '\0';
41         *HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = *FixedQuit = *HideKillsServer = '\0';
42         *DefaultModes = *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
43         *UserStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = *SuffixQuit = '\0';
44         WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0;
45         log_file = NULL;
46         NoUserDns = forcedebug = OperSpyWhois = nofork = HideBans = HideSplits = UndernetMsgPrefix = false;
47         CycleHosts = writelog = AllowHalfop = InvBypassModes = true;
48         dns_timeout = DieDelay = 5;
49         MaxTargets = 20;
50         NetBufferSize = 10240;
51         SoftLimit = Instance->SE->GetMaxFds();
52         MaxConn = SOMAXCONN;
53         MaxWhoResults = 0;
54         debugging = 0;
55         MaxChans = 20;
56         OperMaxChans = 30;
57         c_ipv4_range = 32;
58         c_ipv6_range = 128;
59         maxbans.clear();
60         DNSServerValidator = &ValidateDnsServer;
61 }
62
63 void ServerConfig::ClearStack()
64 {
65         include_stack.clear();
66 }
67
68 void ServerConfig::Update005()
69 {
70         std::stringstream out(data005);
71         std::string token;
72         std::string line5;
73         int token_counter = 0;
74         isupport.clear();
75         while (out >> token)
76         {
77                 line5 = line5 + token + " ";
78                 token_counter++;
79                 if (token_counter >= 13)
80                 {
81                         char buf[MAXBUF];
82                         snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
83                         isupport.push_back(buf);
84                         line5.clear();
85                         token_counter = 0;
86                 }
87         }
88         if (!line5.empty())
89         {
90                 char buf[MAXBUF];
91                 snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
92                 isupport.push_back(buf);
93         }
94 }
95
96 void ServerConfig::Send005(User* user)
97 {
98         for (std::vector<std::string>::iterator line = ServerInstance->Config->isupport.begin(); line != ServerInstance->Config->isupport.end(); line++)
99                 user->WriteNumeric(RPL_ISUPPORT, "%s %s", user->nick.c_str(), line->c_str());
100 }
101
102 bool ServerConfig::CheckOnce(const char* tag, ConfigDataHash &newconf)
103 {
104         int count = ConfValueEnum(newconf, tag);
105
106         if (count > 1)
107                 throw CoreException("You have more than one <"+std::string(tag)+"> tag, this is not permitted.");
108         if (count < 1)
109                 throw CoreException("You have not defined a <"+std::string(tag)+"> tag, this is required.");
110         return true;
111 }
112
113 bool NoValidation(ServerConfig*, const char*, const char*, ValueItem&)
114 {
115         return true;
116 }
117
118 bool DoneConfItem(ServerConfig* conf, const char* tag)
119 {
120         return true;
121 }
122
123 void ServerConfig::ValidateNoSpaces(const char* p, const std::string &tag, const std::string &val)
124 {
125         for (const char* ptr = p; *ptr; ++ptr)
126         {
127                 if (*ptr == ' ')
128                         throw CoreException("The value of <"+tag+":"+val+"> cannot contain spaces");
129         }
130 }
131
132 /* NOTE: Before anyone asks why we're not using inet_pton for this, it is because inet_pton and friends do not return so much detail,
133  * even in strerror(errno). They just return 'yes' or 'no' to an address without such detail as to whats WRONG with the address.
134  * Because ircd users arent as technical as they used to be (;)) we are going to give more of a useful error message.
135  */
136 void ServerConfig::ValidateIP(const char* p, const std::string &tag, const std::string &val, bool wild)
137 {
138         int num_dots = 0;
139         int num_seps = 0;
140         int not_numbers = false;
141         int not_hex = false;
142
143         if (*p)
144         {
145                 if (*p == '.')
146                         throw CoreException("The value of <"+tag+":"+val+"> is not an IP address");
147
148                 for (const char* ptr = p; *ptr; ++ptr)
149                 {
150                         if (wild && (*ptr == '*' || *ptr == '?' || *ptr == '/'))
151                                 continue;
152
153                         if (*ptr != ':' && *ptr != '.')
154                         {
155                                 if (*ptr < '0' || *ptr > '9')
156                                         not_numbers = true;
157                                 if ((*ptr < '0' || *ptr > '9') && (toupper(*ptr) < 'A' || toupper(*ptr) > 'F'))
158                                         not_hex = true;
159                         }
160                         switch (*ptr)
161                         {
162                                 case ' ':
163                                         throw CoreException("The value of <"+tag+":"+val+"> is not an IP address");
164                                 case '.':
165                                         num_dots++;
166                                 break;
167                                 case ':':
168                                         num_seps++;
169                                 break;
170                         }
171                 }
172
173                 if (num_dots > 3)
174                         throw CoreException("The value of <"+tag+":"+val+"> is an IPv4 address with too many fields!");
175
176                 if (num_seps > 8)
177                         throw CoreException("The value of <"+tag+":"+val+"> is an IPv6 address with too many fields!");
178
179                 if (num_seps == 0 && num_dots < 3 && !wild)
180                         throw CoreException("The value of <"+tag+":"+val+"> looks to be a malformed IPv4 address");
181
182                 if (num_seps == 0 && num_dots == 3 && not_numbers)
183                         throw CoreException("The value of <"+tag+":"+val+"> contains non-numeric characters in an IPv4 address");
184
185                 if (num_seps != 0 && not_hex)
186                         throw CoreException("The value of <"+tag+":"+val+"> contains non-hexdecimal characters in an IPv6 address");
187
188                 if (num_seps != 0 && num_dots != 3 && num_dots != 0 && !wild)
189                         throw CoreException("The value of <"+tag+":"+val+"> is a malformed IPv6 4in6 address");
190         }
191 }
192
193 void ServerConfig::ValidateHostname(const char* p, const std::string &tag, const std::string &val)
194 {
195         int num_dots = 0;
196         if (*p)
197         {
198                 if (*p == '.')
199                         throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
200                 for (const char* ptr = p; *ptr; ++ptr)
201                 {
202                         switch (*ptr)
203                         {
204                                 case ' ':
205                                         throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
206                                 case '.':
207                                         num_dots++;
208                                 break;
209                         }
210                 }
211                 if (num_dots == 0)
212                         throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
213         }
214 }
215
216 bool ValidateMaxTargets(ServerConfig* conf, const char*, const char*, ValueItem &data)
217 {
218         if ((data.GetInteger() < 0) || (data.GetInteger() > 31))
219         {
220                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <security:maxtargets> value is greater than 31 or less than 0, set to 20.");
221                 data.Set(20);
222         }
223         return true;
224 }
225
226 bool ValidateSoftLimit(ServerConfig* conf, const char*, const char*, ValueItem &data)
227 {
228         if ((data.GetInteger() < 1) || (data.GetInteger() > conf->GetInstance()->SE->GetMaxFds()))
229         {
230                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <performance:softlimit> value is greater than %d or less than 0, set to %d.",conf->GetInstance()->SE->GetMaxFds(),conf->GetInstance()->SE->GetMaxFds());
231                 data.Set(conf->GetInstance()->SE->GetMaxFds());
232         }
233         return true;
234 }
235
236 bool ValidateMaxConn(ServerConfig* conf, const char*, const char*, ValueItem &data)
237 {
238         if (data.GetInteger() > SOMAXCONN)
239                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <performance:somaxconn> value may be higher than the system-defined SOMAXCONN value!");
240         return true;
241 }
242
243 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance)
244 {
245         std::stringstream dcmds(data);
246         std::string thiscmd;
247
248         /* Enable everything first */
249         for (Commandtable::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
250                 x->second->Disable(false);
251
252         /* Now disable all the ones which the user wants disabled */
253         while (dcmds >> thiscmd)
254         {
255                 Commandtable::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
256                 if (cm != ServerInstance->Parser->cmdlist.end())
257                 {
258                         cm->second->Disable(true);
259                 }
260         }
261         return true;
262 }
263
264 bool ValidateDisabledUModes(ServerConfig* conf, const char*, const char*, ValueItem &data)
265 {
266         memset(conf->DisabledUModes, 0, sizeof(conf->DisabledUModes));
267         for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p)
268         {
269                 if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found.");
270                 conf->DisabledUModes[*p - 'A'] = 1;
271         }
272         return true;
273 }
274
275 bool ValidateDisabledCModes(ServerConfig* conf, const char*, const char*, ValueItem &data)
276 {
277         memset(conf->DisabledCModes, 0, sizeof(conf->DisabledCModes));
278         for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p)
279         {
280                 if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found.");
281                 conf->DisabledCModes[*p - 'A'] = 1;
282         }
283         return true;
284 }
285
286 bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem &data)
287 {
288         if (!*(data.GetString()))
289         {
290                 std::string nameserver;
291                 // attempt to look up their nameserver from /etc/resolv.conf
292                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
293                 std::ifstream resolv("/etc/resolv.conf");
294                 bool found_server = false;
295
296                 if (resolv.is_open())
297                 {
298                         while (resolv >> nameserver)
299                         {
300                                 if ((nameserver == "nameserver") && (!found_server))
301                                 {
302                                         resolv >> nameserver;
303                                         data.Set(nameserver.c_str());
304                                         found_server = true;
305                                         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",nameserver.c_str());
306                                 }
307                         }
308
309                         if (!found_server)
310                         {
311                                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
312                                 data.Set("127.0.0.1");
313                         }
314                 }
315                 else
316                 {
317                         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf can't be opened! Defaulting to nameserver '127.0.0.1'!");
318                         data.Set("127.0.0.1");
319                 }
320         }
321         return true;
322 }
323
324 bool ValidateServerName(ServerConfig* conf, const char*, const char*, ValueItem &data)
325 {
326         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Validating server name");
327         /* If we already have a servername, and they changed it, we should throw an exception. */
328         if (!strchr(data.GetString(), '.'))
329         {
330                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <server:name> '%s' is not a fully-qualified domain name. Changed to '%s%c'",data.GetString(),data.GetString(),'.');
331                 std::string moo = std::string(data.GetString()).append(".");
332                 data.Set(moo.c_str());
333         }
334         conf->ValidateHostname(data.GetString(), "server", "name");
335         return true;
336 }
337
338 bool ValidateNetBufferSize(ServerConfig* conf, const char*, const char*, ValueItem &data)
339 {
340         // 65534 not 65535 because of null terminator
341         if ((!data.GetInteger()) || (data.GetInteger() > 65534) || (data.GetInteger() < 1024))
342         {
343                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240.");
344                 data.Set(10240);
345         }
346         return true;
347 }
348
349 bool ValidateMaxWho(ServerConfig* conf, const char*, const char*, ValueItem &data)
350 {
351         if ((data.GetInteger() > 65535) || (data.GetInteger() < 1))
352         {
353                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"<performance:maxwho> size out of range, setting to default of 128.");
354                 data.Set(128);
355         }
356         return true;
357 }
358
359 bool ValidateMotd(ServerConfig* conf, const char*, const char*, ValueItem &data)
360 {
361         conf->ReadFile(conf->MOTD, data.GetString());
362         return true;
363 }
364
365 bool ValidateNotEmpty(ServerConfig*, const char* tag, const char* val, ValueItem &data)
366 {
367         if (!*data.GetString())
368                 throw CoreException(std::string("The value for <")+tag+":"+val+"> cannot be empty!");
369         return true;
370 }
371
372 bool ValidateRules(ServerConfig* conf, const char*, const char*, ValueItem &data)
373 {
374         conf->ReadFile(conf->RULES, data.GetString());
375         return true;
376 }
377
378 bool ValidateModeLists(ServerConfig* conf, const char*, const char*, ValueItem &data)
379 {
380         memset(conf->HideModeLists, 0, sizeof(conf->HideModeLists));
381         for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
382                 conf->HideModeLists[*x] = true;
383         return true;
384 }
385
386 bool ValidateExemptChanOps(ServerConfig* conf, const char*, const char*, ValueItem &data)
387 {
388         memset(conf->ExemptChanOps, 0, sizeof(conf->ExemptChanOps));
389         for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
390                 conf->ExemptChanOps[*x] = true;
391         return true;
392 }
393
394 bool ValidateInvite(ServerConfig* conf, const char*, const char*, ValueItem &data)
395 {
396         std::string v = data.GetString();
397
398         if (v == "ops")
399                 conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS;
400         else if (v == "all")
401                 conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL;
402         else if (v == "dynamic")
403                 conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC;
404         else
405                 conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE;
406
407         return true;
408 }
409
410 bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem &data)
411 {
412         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Validating server id");
413
414         const char *sid = data.GetString();
415
416         if (*sid && !conf->GetInstance()->IsSID(sid))
417         {
418                 throw CoreException(std::string(sid) + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
419         }
420
421         strlcpy(conf->sid, sid, 5);
422
423         return true;
424 }
425
426 bool ValidateWhoWas(ServerConfig* conf, const char*, const char*, ValueItem &data)
427 {
428         conf->WhoWasMaxKeep = conf->GetInstance()->Duration(data.GetString());
429
430         if (conf->WhoWasGroupSize < 0)
431                 conf->WhoWasGroupSize = 0;
432
433         if (conf->WhoWasMaxGroups < 0)
434                 conf->WhoWasMaxGroups = 0;
435
436         if (conf->WhoWasMaxKeep < 3600)
437         {
438                 conf->WhoWasMaxKeep = 3600;
439                 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <whowas:maxkeep> value less than 3600, setting to default 3600");
440         }
441
442         Command* whowas_command = conf->GetInstance()->Parser->GetHandler("WHOWAS");
443         if (whowas_command)
444         {
445                 std::deque<classbase*> params;
446                 whowas_command->HandleInternal(WHOWAS_PRUNE, params);
447         }
448
449         return true;
450 }
451
452 /* Callback called before processing the first <connect> tag
453  */
454 bool InitConnect(ServerConfig* conf, const char*)
455 {
456         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Reading connect classes...");
457
458         for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end() ; )
459         {
460                 ConnectClass* c = *i;
461
462                 /* only delete a class with refcount 0 */
463                 if (c->RefCount == 0)
464                 {
465                         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Removing connect class, refcount is 0!");
466                         
467                         /* This was causing a crash, because we'd set i to .begin() just here, but then the for loop's increment would
468                          * set it to .begin() + 1. Which if it was already the last thing in the list, wasn't good.
469                          * Now the increment is in the else { } below.
470                          */
471                         conf->Classes.erase(i);
472                         i = conf->Classes.begin(); // start over so we don't trample on a bad iterator
473                 }
474                 else
475                 {
476                         /* also mark all existing classes disabled, if they still exist in the conf, they will be reenabled. */
477                         c->SetDisabled(true);
478                         i++;
479                 }
480         }
481
482         return true;
483 }
484
485 /* Callback called to process a single <connect> tag
486  */
487 bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
488 {
489         ConnectClass c;
490         const char* allow = values[0].GetString(); /* Yeah, there are a lot of values. Live with it. */
491         const char* deny = values[1].GetString();
492         const char* password = values[2].GetString();
493         int timeout = values[3].GetInteger();
494         int pingfreq = values[4].GetInteger();
495         int flood = values[5].GetInteger();
496         int threshold = values[6].GetInteger();
497         int sendq = values[7].GetInteger();
498         int recvq = values[8].GetInteger();
499         int localmax = values[9].GetInteger();
500         int globalmax = values[10].GetInteger();
501         int port = values[11].GetInteger();
502         const char* name = values[12].GetString();
503         const char* parent = values[13].GetString();
504         int maxchans = values[14].GetInteger();
505         unsigned long limit = values[15].GetInteger();
506         const char* hashtype = values[16].GetString();
507
508         /*
509          * duplicates check: Now we don't delete all connect classes on rehash, we need to ensure we don't add dupes.
510          * easier said than done, but for now we'll just disallow anything with a duplicate host or name. -- w00t
511          */
512         for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
513         {
514                 ConnectClass* cc = *item;
515                 if (
516                          ((*name && (cc->GetName() == name)) || // if the name is the same
517                          (*allow && (cc->GetHost() == allow)) || // or the allow is the same
518                          (*deny && (cc->GetHost() == deny))) && // or the deny is the same
519                          (!port || (port && (cc->GetPort() == port))) // and there is no port, or there is a port and the port is the same
520                    )
521                 {
522                         /* reenable class so users can be shoved into it :P */
523                         cc->SetDisabled(false);
524                         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Not adding class, it already exists!");
525                         return true;
526                 } 
527         }
528
529         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Adding a connect class!");
530
531         if (*parent)
532         {
533                 /* Find 'parent' and inherit a new class from it,
534                  * then overwrite any values that are set here
535                  */
536                 ClassVector::iterator item = conf->Classes.begin();
537                 for (; item != conf->Classes.end(); ++item)
538                 {
539                         ConnectClass* cc = *item;
540                         conf->GetInstance()->Logs->Log("CONFIG",DEBUG,"Class: %s", cc->GetName().c_str());
541                         if (cc->GetName() == parent)
542                         {
543                                 ConnectClass* newclass = new ConnectClass(name, cc);
544                                 newclass->Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
545                                 conf->Classes.push_back(newclass);
546                                 break;
547                         }
548                 }
549                 if (item == conf->Classes.end())
550                         throw CoreException("Class name '" + std::string(name) + "' is configured to inherit from class '" + std::string(parent) + "' which cannot be found.");
551         }
552         else
553         {
554                 if (*allow)
555                 {
556                         /* Find existing class by mask, the mask should be unique */
557                         for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
558                         {
559                                 if ((*item)->GetHost() == allow)
560                                 {
561                                         (*item)->Update(timeout, flood, allow, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
562                                         return true;
563                                 }
564                         }
565                         ConnectClass* cc = new ConnectClass(name, timeout, flood, allow, pingfreq, password, hashtype, threshold, sendq, recvq, localmax, globalmax, maxchans);
566                         cc->limit = limit;
567                         cc->SetPort(port);
568                         conf->Classes.push_back(cc);
569                 }
570                 else
571                 {
572                         /* Find existing class by mask, the mask should be unique */
573                         for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
574                         {
575                                 if ((*item)->GetHost() == deny)
576                                 {
577                                         (*item)->Update(name, deny);
578                                         (*item)->SetPort(port);
579                                         return true;
580                                 }
581                         }
582                         ConnectClass* cc = new ConnectClass(name, deny);
583                         cc->SetPort(port);
584                         conf->Classes.push_back(cc);
585                 }
586         }
587
588         return true;
589 }
590
591 /* Callback called when there are no more <connect> tags
592  */
593 bool DoneConnect(ServerConfig *conf, const char*)
594 {
595         conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Done adding connect classes!");
596         return true;
597 }
598
599 /* Callback called before processing the first <uline> tag
600  */
601 bool InitULine(ServerConfig* conf, const char*)
602 {
603         conf->ulines.clear();
604         return true;
605 }
606
607 /* Callback called to process a single <uline> tag
608  */
609 bool DoULine(ServerConfig* conf, const char*, char**, ValueList &values, int*)
610 {
611         const char* server = values[0].GetString();
612         const bool silent = values[1].GetBool();
613         conf->ulines[server] = silent;
614         return true;
615 }
616
617 /* Callback called when there are no more <uline> tags
618  */
619 bool DoneULine(ServerConfig*, const char*)
620 {
621         return true;
622 }
623
624 /* Callback called before processing the first <module> tag
625  */
626 bool InitModule(ServerConfig* conf, const char*)
627 {
628         old_module_names = conf->GetInstance()->Modules->GetAllModuleNames(0);
629         new_module_names.clear();
630         added_modules.clear();
631         removed_modules.clear();
632         return true;
633 }
634
635 /* Callback called to process a single <module> tag
636  */
637 bool DoModule(ServerConfig*, const char*, char**, ValueList &values, int*)
638 {
639         const char* modname = values[0].GetString();
640         new_module_names.push_back(modname);
641         return true;
642 }
643
644 /* Callback called when there are no more <module> tags
645  */
646 bool DoneModule(ServerConfig*, const char*)
647 {
648         // now create a list of new modules that are due to be loaded
649         // and a seperate list of modules which are due to be unloaded
650         for (std::vector<std::string>::iterator _new = new_module_names.begin(); _new != new_module_names.end(); _new++)
651         {
652                 bool added = true;
653
654                 for (std::vector<std::string>::iterator old = old_module_names.begin(); old != old_module_names.end(); old++)
655                 {
656                         if (*old == *_new)
657                                 added = false;
658                 }
659
660                 if (added)
661                         added_modules.push_back(*_new);
662         }
663
664         for (std::vector<std::string>::iterator oldm = old_module_names.begin(); oldm != old_module_names.end(); oldm++)
665         {
666                 bool removed = true;
667                 for (std::vector<std::string>::iterator newm = new_module_names.begin(); newm != new_module_names.end(); newm++)
668                 {
669                         if (*newm == *oldm)
670                                 removed = false;
671                 }
672
673                 if (removed)
674                         removed_modules.push_back(*oldm);
675         }
676         return true;
677 }
678
679 /* Callback called before processing the first <banlist> tag
680  */
681 bool InitMaxBans(ServerConfig* conf, const char*)
682 {
683         conf->maxbans.clear();
684         return true;
685 }
686
687 /* Callback called to process a single <banlist> tag
688  */
689 bool DoMaxBans(ServerConfig* conf, const char*, char**, ValueList &values, int*)
690 {
691         const char* channel = values[0].GetString();
692         int limit = values[1].GetInteger();
693         conf->maxbans[channel] = limit;
694         return true;
695 }
696
697 /* Callback called when there are no more <banlist> tags.
698  */
699 bool DoneMaxBans(ServerConfig*, const char*)
700 {
701         return true;
702 }
703
704 void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, const std::string &useruid)
705 {
706         ServerInstance->Logs->Log("CONFIG",DEFAULT, "There were errors in your configuration file: %s", errormessage.c_str());
707         if (bail)
708         {
709                 /* Unneeded because of the ServerInstance->Log() aboive? */
710                 printf("There were errors in your configuration:\n%s\n\n",errormessage.c_str());
711                 ServerInstance->Exit(EXIT_STATUS_CONFIG);
712         }
713         else
714         {
715                 std::string errors = errormessage;
716                 std::string::size_type start;
717                 unsigned int prefixlen;
718                 start = 0;
719                 /* ":ServerInstance->Config->ServerName NOTICE user->nick :" */
720                 if (!useruid.empty())
721                 {
722                         User* user = ServerInstance->FindNick(useruid);
723                         if (user)
724                         {
725                                 prefixlen = strlen(this->ServerName) + user->nick.length() + 11;
726                                 user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick.c_str());
727                                 while (start < errors.length())
728                                 {
729                                         user->WriteServ("NOTICE %s :%s",user->nick.c_str(), errors.substr(start, 510 - prefixlen).c_str());
730                                         start += 510 - prefixlen;
731                                 }
732                         }
733                 }
734                 else
735                 {
736                         ServerInstance->SNO->WriteToSnoMask('A', "There were errors in the configuration file:");
737                         while (start < errors.length())
738                         {
739                                 ServerInstance->SNO->WriteToSnoMask('A', errors.substr(start, 360));
740                                 start += 360;
741                         }
742                 }
743                 return;
744         }
745 }
746
747 void ServerConfig::Read(bool bail, const std::string &useruid)
748 {
749         int rem = 0, add = 0;      /* Number of modules added, number of modules removed */
750
751         static char maxkeep[MAXBUF];    /* Temporary buffer for WhoWasMaxKeep value */
752         static char hidemodes[MAXBUF];  /* Modes to not allow listing from users below halfop */
753         static char exemptchanops[MAXBUF];      /* Exempt channel ops from these modes */
754         static char announceinvites[MAXBUF];    /* options:announceinvites setting */
755         static char disabledumodes[MAXBUF]; /* Disabled usermodes */
756         static char disabledcmodes[MAXBUF]; /* Disabled chanmodes */
757         errstr.clear();
758
759         include_stack.clear();
760
761         /* These tags MUST occur and must ONLY occur once in the config file */
762         static const char* Once[] = { "server", "admin", "files", "power", "options", NULL };
763
764         Deprecated ChangedConfig[] = {
765                 {"options",     "hidelinks",            "has been moved to <security:hidelinks> as of 1.2a3"},
766                 {"options",     "hidewhois",            "has been moved to <security:hidewhois> as of 1.2a3"},
767                 {"options",     "userstats",            "has been moved to <security:userstats> as of 1.2a3"},
768                 {"options",     "customversion",        "has been moved to <security:customversion> as of 1.2a3"},
769                 {"options",     "hidesplits",           "has been moved to <security:hidesplits> as of 1.2a3"},
770                 {"options",     "hidebans",             "has been moved to <security:hidebans> as of 1.2a3"},
771                 {"options",     "hidekills",            "has been moved to <security:hidekills> as of 1.2a3"},
772                 {"options",     "operspywhois",         "has been moved to <security:operspywhois> as of 1.2a3"},
773                 {"options",     "announceinvites",      "has been moved to <security:announceinvites> as of 1.2a3"},
774                 {"options",     "hidemodes",            "has been moved to <security:hidemodes> as of 1.2a3"},
775                 {"options",     "maxtargets",           "has been moved to <security:maxtargets> as of 1.2a3"},
776                 {"options",     "nouserdns",            "has been moved to <performance:nouserdns> as of 1.2a3"},
777                 {"options",     "maxwho",               "has been moved to <performance:maxwho> as of 1.2a3"},
778                 {"options",     "softlimit",            "has been moved to <performance:softlimit> as of 1.2a3"},
779                 {"options",     "somaxconn",            "has been moved to <performance:somaxconn> as of 1.2a3"},
780                 {"options",     "netbuffersize",        "has been moved to <performance:netbuffersize> as of 1.2a3"},
781                 {"options",     "maxwho",               "has been moved to <performance:maxwho> as of 1.2a3"},
782                 {"options",     "loglevel",             "1.2 does not use the loglevel value. Please define <log> tags instead."},
783                 {NULL,          NULL,                   NULL}
784         };
785
786         /* These tags can occur ONCE or not at all */
787         InitialConfig Values[] = {
788                 {"performance", "softlimit",    "0",                    new ValueContainerUInt (&this->SoftLimit),              DT_INTEGER,  ValidateSoftLimit},
789                 {"performance", "somaxconn",    SOMAXCONN_S,            new ValueContainerInt  (&this->MaxConn),                DT_INTEGER,  ValidateMaxConn},
790                 {"options",     "moronbanner",  "Youre banned!",        new ValueContainerChar (this->MoronBanner),             DT_CHARPTR,  NoValidation},
791                 {"server",      "name",         "",                     new ValueContainerChar (this->ServerName),              DT_HOSTNAME|DT_BOOTONLY, ValidateServerName},
792                 {"server",      "description",  "Configure Me",         new ValueContainerChar (this->ServerDesc),              DT_CHARPTR,  NoValidation},
793                 {"server",      "network",      "Network",              new ValueContainerChar (this->Network),                 DT_NOSPACES, NoValidation},
794                 {"server",      "id",           "",                     new ValueContainerChar (this->sid),                     DT_CHARPTR|DT_BOOTONLY,  ValidateSID},
795                 {"admin",       "name",         "",                     new ValueContainerChar (this->AdminName),               DT_CHARPTR,  NoValidation},
796                 {"admin",       "email",        "Mis@configu.red",      new ValueContainerChar (this->AdminEmail),              DT_CHARPTR,  NoValidation},
797                 {"admin",       "nick",         "Misconfigured",        new ValueContainerChar (this->AdminNick),               DT_CHARPTR,  NoValidation},
798                 {"files",       "motd",         "",                     new ValueContainerChar (this->motd),                    DT_CHARPTR,  ValidateMotd},
799                 {"files",       "rules",        "",                     new ValueContainerChar (this->rules),                   DT_CHARPTR,  ValidateRules},
800                 {"power",       "diepass",      "",                     new ValueContainerChar (this->diepass),                 DT_CHARPTR,  ValidateNotEmpty},
801                 {"power",       "pause",        "",                     new ValueContainerInt  (&this->DieDelay),               DT_INTEGER,  NoValidation},
802                 {"power",       "hash",         "",                     new ValueContainerChar (this->powerhash),               DT_CHARPTR,  NoValidation},
803                 {"power",       "restartpass",  "",                     new ValueContainerChar (this->restartpass),             DT_CHARPTR,  ValidateNotEmpty},
804                 {"options",     "prefixquit",   "",                     new ValueContainerChar (this->PrefixQuit),              DT_CHARPTR,  NoValidation},
805                 {"options",     "suffixquit",   "",                     new ValueContainerChar (this->SuffixQuit),              DT_CHARPTR,  NoValidation},
806                 {"options",     "fixedquit",    "",                     new ValueContainerChar (this->FixedQuit),               DT_CHARPTR,  NoValidation},
807                 {"options",     "prefixpart",   "",                     new ValueContainerChar (this->PrefixPart),              DT_CHARPTR,  NoValidation},
808                 {"options",     "suffixpart",   "",                     new ValueContainerChar (this->SuffixPart),              DT_CHARPTR,  NoValidation},
809                 {"options",     "fixedpart",    "",                     new ValueContainerChar (this->FixedPart),               DT_CHARPTR,  NoValidation},
810                 {"performance", "netbuffersize","10240",                new ValueContainerInt  (&this->NetBufferSize),          DT_INTEGER,  ValidateNetBufferSize},
811                 {"performance", "maxwho",       "128",                  new ValueContainerInt  (&this->MaxWhoResults),          DT_INTEGER,  ValidateMaxWho},
812                 {"options",     "allowhalfop",  "0",                    new ValueContainerBool (&this->AllowHalfop),            DT_BOOLEAN,  NoValidation},
813                 {"dns",         "server",       "",                     new ValueContainerChar (this->DNSServer),               DT_IPADDRESS,DNSServerValidator},
814                 {"dns",         "timeout",      "5",                    new ValueContainerInt  (&this->dns_timeout),            DT_INTEGER,  NoValidation},
815                 {"options",     "moduledir",    MOD_PATH,               new ValueContainerChar (this->ModPath),                 DT_CHARPTR,  NoValidation},
816                 {"disabled",    "commands",     "",                     new ValueContainerChar (this->DisabledCommands),        DT_CHARPTR,  NoValidation},
817                 {"disabled",    "usermodes",    "",                     new ValueContainerChar (disabledumodes),                DT_CHARPTR,  ValidateDisabledUModes},
818                 {"disabled",    "chanmodes",    "",                     new ValueContainerChar (disabledcmodes),                DT_CHARPTR,  ValidateDisabledCModes},
819                 {"disabled",    "fakenonexistant",      "0",                    new ValueContainerBool (&this->DisabledDontExist),              DT_BOOLEAN,  NoValidation},
820                 {"security",    "userstats",    "",                     new ValueContainerChar (this->UserStats),               DT_CHARPTR,  NoValidation},
821                 {"security",    "customversion","",                     new ValueContainerChar (this->CustomVersion),           DT_CHARPTR,  NoValidation},
822                 {"security",    "hidesplits",   "0",                    new ValueContainerBool (&this->HideSplits),             DT_BOOLEAN,  NoValidation},
823                 {"security",    "hidebans",     "0",                    new ValueContainerBool (&this->HideBans),               DT_BOOLEAN,  NoValidation},
824                 {"security",    "hidewhois",    "",                     new ValueContainerChar (this->HideWhoisServer),         DT_NOSPACES, NoValidation},
825                 {"security",    "hidekills",    "",                     new ValueContainerChar (this->HideKillsServer),         DT_NOSPACES,  NoValidation},
826                 {"security",    "operspywhois", "0",                    new ValueContainerBool (&this->OperSpyWhois),           DT_BOOLEAN,  NoValidation},
827                 {"performance", "nouserdns",    "0",                    new ValueContainerBool (&this->NoUserDns),              DT_BOOLEAN,  NoValidation},
828                 {"options",     "syntaxhints",  "0",                    new ValueContainerBool (&this->SyntaxHints),            DT_BOOLEAN,  NoValidation},
829                 {"options",     "cyclehosts",   "0",                    new ValueContainerBool (&this->CycleHosts),             DT_BOOLEAN,  NoValidation},
830                 {"options",     "ircumsgprefix","0",                    new ValueContainerBool (&this->UndernetMsgPrefix),      DT_BOOLEAN,  NoValidation},
831                 {"security",    "announceinvites", "1",                 new ValueContainerChar (announceinvites),               DT_CHARPTR,  ValidateInvite},
832                 {"options",     "hostintopic",  "1",                    new ValueContainerBool (&this->FullHostInTopic),        DT_BOOLEAN,  NoValidation},
833                 {"security",    "hidemodes",    "",                     new ValueContainerChar (hidemodes),                     DT_CHARPTR,  ValidateModeLists},
834                 {"options",     "exemptchanops","",                     new ValueContainerChar (exemptchanops),                 DT_CHARPTR,  ValidateExemptChanOps},
835                 {"security",    "maxtargets",   "20",                   new ValueContainerUInt (&this->MaxTargets),             DT_INTEGER,  ValidateMaxTargets},
836                 {"options",     "defaultmodes", "nt",                   new ValueContainerChar (this->DefaultModes),            DT_CHARPTR,  NoValidation},
837                 {"pid",         "file",         "",                     new ValueContainerChar (this->PID),                     DT_CHARPTR,  NoValidation},
838                 {"whowas",      "groupsize",    "10",                   new ValueContainerInt  (&this->WhoWasGroupSize),        DT_INTEGER,  NoValidation},
839                 {"whowas",      "maxgroups",    "10240",                new ValueContainerInt  (&this->WhoWasMaxGroups),        DT_INTEGER,  NoValidation},
840                 {"whowas",      "maxkeep",      "3600",                 new ValueContainerChar (maxkeep),                       DT_CHARPTR,  ValidateWhoWas},
841                 {"die",         "value",        "",                     new ValueContainerChar (this->DieValue),                DT_CHARPTR,  NoValidation},
842                 {"channels",    "users",        "20",                   new ValueContainerUInt (&this->MaxChans),               DT_INTEGER,  NoValidation},
843                 {"channels",    "opers",        "60",                   new ValueContainerUInt (&this->OperMaxChans),           DT_INTEGER,  NoValidation},
844                 {"cidr",        "ipv4clone",    "32",                   new ValueContainerInt (&this->c_ipv4_range),            DT_INTEGER,  NoValidation},
845                 {"cidr",        "ipv6clone",    "128",                  new ValueContainerInt (&this->c_ipv6_range),            DT_INTEGER,  NoValidation},
846                 {"limits",      "maxnick",      "32",                   new ValueContainerST (&this->Limits.NickMax),           DT_INTEGER,  NoValidation},
847                 {"limits",      "maxchan",      "64",                   new ValueContainerST (&this->Limits.ChanMax),           DT_INTEGER,  NoValidation},
848                 {"limits",      "maxmodes",     "20",                   new ValueContainerST (&this->Limits.MaxModes),          DT_INTEGER,  NoValidation},
849                 {"limits",      "maxident",     "11",                   new ValueContainerST (&this->Limits.IdentMax),          DT_INTEGER,  NoValidation},
850                 {"limits",      "maxquit",      "255",                  new ValueContainerST (&this->Limits.MaxQuit),           DT_INTEGER,  NoValidation},
851                 {"limits",      "maxtopic",     "307",                  new ValueContainerST (&this->Limits.MaxTopic),          DT_INTEGER,  NoValidation},
852                 {"limits",      "maxkick",      "255",                  new ValueContainerST (&this->Limits.MaxKick),           DT_INTEGER,  NoValidation},
853                 {"limits",      "maxgecos",     "128",                  new ValueContainerST (&this->Limits.MaxGecos),          DT_INTEGER,  NoValidation},
854                 {"limits",      "maxaway",      "200",                  new ValueContainerST (&this->Limits.MaxAway),           DT_INTEGER,  NoValidation},
855                 {"options",     "invitebypassmodes",    "1",                    new ValueContainerBool (&this->InvBypassModes),         DT_BOOLEAN,  NoValidation},
856                 {NULL,          NULL,           NULL,                   NULL,                                                   DT_NOTHING,  NoValidation}
857         };
858
859
860         /* These tags can occur multiple times, and therefore they have special code to read them
861          * which is different to the code for reading the singular tags listed above.
862          */
863         MultiConfig MultiValues[] = {
864
865                 {"connect",
866                                 {"allow",       "deny",         "password",     "timeout",      "pingfreq",     "flood",
867                                 "threshold",    "sendq",        "recvq",        "localmax",     "globalmax",    "port",
868                                 "name",         "parent",       "maxchans",     "limit",        "hash",
869                                 NULL},
870                                 {"",            "",             "",             "",             "120",          "",
871                                  "",            "",             "",             "3",            "3",            "0",
872                                  "",            "",             "0",        "0",        "",
873                                  NULL},
874                                 {DT_IPADDRESS|DT_ALLOW_WILD,
875                                                 DT_IPADDRESS|DT_ALLOW_WILD,
876                                                                 DT_CHARPTR,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,
877                                 DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,
878                                 DT_NOSPACES,    DT_NOSPACES,    DT_INTEGER,     DT_INTEGER,     DT_CHARPTR},
879                                 InitConnect, DoConnect, DoneConnect},
880
881                 {"uline",
882                                 {"server",      "silent",       NULL},
883                                 {"",            "0",            NULL},
884                                 {DT_HOSTNAME,   DT_BOOLEAN},
885                                 InitULine,DoULine,DoneULine},
886
887                 {"banlist",
888                                 {"chan",        "limit",        NULL},
889                                 {"",            "",             NULL},
890                                 {DT_CHARPTR,    DT_INTEGER},
891                                 InitMaxBans, DoMaxBans, DoneMaxBans},
892
893                 {"module",
894                                 {"name",        NULL},
895                                 {"",            NULL},
896                                 {DT_CHARPTR},
897                                 InitModule, DoModule, DoneModule},
898
899                 {"badip",
900                                 {"reason",      "ipmask",       NULL},
901                                 {"No reason",   "",             NULL},
902                                 {DT_CHARPTR,    DT_IPADDRESS|DT_ALLOW_WILD},
903                                 InitXLine, DoZLine, DoneConfItem},
904
905                 {"badnick",
906                                 {"reason",      "nick",         NULL},
907                                 {"No reason",   "",             NULL},
908                                 {DT_CHARPTR,    DT_CHARPTR},
909                                 InitXLine, DoQLine, DoneConfItem},
910         
911                 {"badhost",
912                                 {"reason",      "host",         NULL},
913                                 {"No reason",   "",             NULL},
914                                 {DT_CHARPTR,    DT_CHARPTR},
915                                 InitXLine, DoKLine, DoneConfItem},
916
917                 {"exception",
918                                 {"reason",      "host",         NULL},
919                                 {"No reason",   "",             NULL},
920                                 {DT_CHARPTR,    DT_CHARPTR},
921                                 InitXLine, DoELine, DoneELine},
922         
923                 {"type",
924                                 {"name",        "classes",      NULL},
925                                 {"",            "",             NULL},
926                                 {DT_NOSPACES,   DT_CHARPTR},
927                                 InitTypes, DoType, DoneClassesAndTypes},
928
929                 {"class",
930                                 {"name",        "commands",     "usermodes",    "chanmodes",    NULL},
931                                 {"",            "",             "",             "",             NULL},
932                                 {DT_NOSPACES,   DT_CHARPTR,     DT_CHARPTR,     DT_CHARPTR},
933                                 InitClasses, DoClass, DoneClassesAndTypes},
934         
935                 {NULL,
936                                 {NULL},
937                                 {NULL},
938                                 {0},
939                                 NULL, NULL, NULL}
940         };
941
942         /* Load and parse the config file, if there are any errors then explode */
943
944         /* Make a copy here so if it fails then we can carry on running with an unaffected config */
945         newconfig.clear();
946
947         if (!this->DoInclude(newconfig, ServerInstance->ConfigFileName, errstr))
948         {
949                 ReportConfigError(errstr.str(), bail, useruid);
950                 return;
951         }
952
953         /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */
954         try
955         {
956                 /* Check we dont have more than one of singular tags, or any of them missing
957                  */
958                 for (int Index = 0; Once[Index]; Index++)
959                         if (!CheckOnce(Once[Index], newconfig))
960                                 return;
961
962                 for (int Index = 0; ChangedConfig[Index].tag; Index++)
963                 {
964                         char item[MAXBUF];
965                         *item = 0;
966                         if (ConfValue(newconfig, ChangedConfig[Index].tag, ChangedConfig[Index].value, "", 0, item, MAXBUF, true) || *item)
967                                 throw CoreException(std::string("Your configuration contains a deprecated value: <") + ChangedConfig[Index].tag + ":" + ChangedConfig[Index].value + "> - " + ChangedConfig[Index].reason);
968                         else
969                                 ServerInstance->Logs->Log("CONFIG",DEBUG,"Deprecated item <%s:%s> does not exist, good.", ChangedConfig[Index].tag, ChangedConfig[Index].value);
970                 }
971
972                 /* Read the values of all the tags which occur once or not at all, and call their callbacks.
973                  */
974                 for (int Index = 0; Values[Index].tag; ++Index)
975                 {
976                         char item[MAXBUF];
977                         int dt = Values[Index].datatype;
978                         bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0);
979                         bool allow_wild = ((dt & DT_ALLOW_WILD) > 0);
980                         bool bootonly = ((dt & DT_BOOTONLY) > 0);
981                         dt &= ~DT_ALLOW_NEWLINE;
982                         dt &= ~DT_ALLOW_WILD;
983                         dt &= ~DT_BOOTONLY;
984
985                         /* Silently ignore boot only values */
986                         if (bootonly && !bail)
987                                 continue;
988
989                         ConfValue(newconfig, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, MAXBUF, allow_newlines);
990                         ValueItem vi(item);
991                         
992                         if (!Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi))
993                                 throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
994         
995                         ServerInstance->Threads->Lock();
996                         switch (dt)
997                         {
998                                 case DT_NOSPACES:
999                                 {
1000                                         ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1001                                         this->ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value);
1002                                         vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1003                                 }
1004                                 break;
1005                                 case DT_HOSTNAME:
1006                                 {
1007                                         ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1008                                         this->ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value);
1009                                         vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1010                                 }
1011                                 break;
1012                                 case DT_IPADDRESS:
1013                                 {
1014                                         ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1015                                         this->ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild);
1016                                         vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1017                                 }
1018                                 break;
1019                                 case DT_CHANNEL:
1020                                 {
1021                                         ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1022                                         if (*(vi.GetString()) && !ServerInstance->IsChannel(vi.GetString(), MAXBUF))
1023                                         {
1024                                                 ServerInstance->Threads->Unlock();
1025                                                 throw CoreException("The value of <"+std::string(Values[Index].tag)+":"+Values[Index].value+"> is not a valid channel name");
1026                                         }
1027                                         vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1028                                 }
1029                                 break;
1030                                 case DT_CHARPTR:
1031                                 {
1032                                         ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1033                                         /* Make sure we also copy the null terminator */
1034                                         vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1035                                 }
1036                                 break;
1037                                 case DT_INTEGER:
1038                                 {
1039                                         int val = vi.GetInteger();
1040                                         ValueContainerInt* vci = (ValueContainerInt*)Values[Index].val;
1041                                         vci->Set(&val, sizeof(int));
1042                                 }
1043                                 break;
1044                                 case DT_BOOLEAN:
1045                                 {
1046                                         bool val = vi.GetBool();
1047                                         ValueContainerBool* vcb = (ValueContainerBool*)Values[Index].val;
1048                                         vcb->Set(&val, sizeof(bool));
1049                                 }
1050                                 break;
1051                                 default:
1052                                         /* You don't want to know what happens if someones bad code sends us here. */
1053                                 break;
1054                         }
1055                         /* We're done with this now */
1056                         delete Values[Index].val;
1057                         ServerInstance->Threads->Unlock();
1058                 }
1059
1060                 /* Read the multiple-tag items (class tags, connect tags, etc)
1061                  * and call the callbacks associated with them. We have three
1062                  * callbacks for these, a 'start', 'item' and 'end' callback.
1063                  */
1064                 for (int Index = 0; MultiValues[Index].tag; ++Index)
1065                 {
1066                         ServerInstance->Threads->Lock();
1067                         MultiValues[Index].init_function(this, MultiValues[Index].tag);
1068                         ServerInstance->Threads->Unlock();
1069
1070                         int number_of_tags = ConfValueEnum(newconfig, MultiValues[Index].tag);
1071
1072                         for (int tagnum = 0; tagnum < number_of_tags; ++tagnum)
1073                         {
1074                                 ValueList vl;
1075                                 for (int valuenum = 0; (MultiValues[Index].items[valuenum]) && (valuenum < MAX_VALUES_PER_TAG); ++valuenum)
1076                                 {
1077                                         int dt = MultiValues[Index].datatype[valuenum];
1078                                         bool allow_newlines =  ((dt & DT_ALLOW_NEWLINE) > 0);
1079                                         bool allow_wild = ((dt & DT_ALLOW_WILD) > 0);
1080                                         dt &= ~DT_ALLOW_NEWLINE;
1081                                         dt &= ~DT_ALLOW_WILD;
1082
1083                                         ServerInstance->Threads->Lock();
1084                                         /* We catch and rethrow any exception here just so we can free our mutex
1085                                          */
1086                                         try
1087                                         {
1088                                                 switch (dt)
1089                                                 {
1090                                                         case DT_NOSPACES:
1091                                                         {
1092                                                                 char item[MAXBUF];
1093                                                                 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1094                                                                         vl.push_back(ValueItem(item));
1095                                                                 else
1096                                                                         vl.push_back(ValueItem(""));
1097                                                                 this->ValidateNoSpaces(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
1098                                                         }
1099                                                         break;
1100                                                         case DT_HOSTNAME:
1101                                                         {
1102                                                                 char item[MAXBUF];
1103                                                                 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1104                                                                         vl.push_back(ValueItem(item));
1105                                                                 else
1106                                                                         vl.push_back(ValueItem(""));
1107                                                                 this->ValidateHostname(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
1108                                                         }
1109                                                         break;
1110                                                         case DT_IPADDRESS:
1111                                                         {
1112                                                                 char item[MAXBUF];
1113                                                                 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1114                                                                         vl.push_back(ValueItem(item));
1115                                                                 else
1116                                                                         vl.push_back(ValueItem(""));
1117                                                                 this->ValidateIP(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild);
1118                                                         }
1119                                                         break;
1120                                                         case DT_CHANNEL:
1121                                                         {
1122                                                                 char item[MAXBUF];
1123                                                                 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1124                                                                         vl.push_back(ValueItem(item));
1125                                                                 else
1126                                                                         vl.push_back(ValueItem(""));
1127                                                                 if (!ServerInstance->IsChannel(vl[vl.size()-1].GetString(), MAXBUF))
1128                                                                         throw CoreException("The value of <"+std::string(MultiValues[Index].tag)+":"+MultiValues[Index].items[valuenum]+"> number "+ConvToStr(tagnum + 1)+" is not a valid channel name");
1129                                                         }
1130                                                         break;
1131                                                         case DT_CHARPTR:
1132                                                         {
1133                                                                 char item[MAXBUF];
1134                                                                 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1135                                                                         vl.push_back(ValueItem(item));
1136                                                                 else
1137                                                                         vl.push_back(ValueItem(""));
1138                                                         }
1139                                                         break;
1140                                                         case DT_INTEGER:
1141                                                         {
1142                                                                 int item = 0;
1143                                                                 if (ConfValueInteger(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item))
1144                                                                         vl.push_back(ValueItem(item));
1145                                                                 else
1146                                                                         vl.push_back(ValueItem(0));
1147                                                         }
1148                                                         break;
1149                                                         case DT_BOOLEAN:
1150                                                         {
1151                                                                 bool item = ConfValueBool(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum);
1152                                                                 vl.push_back(ValueItem(item));
1153                                                         }
1154                                                         break;
1155                                                         default:
1156                                                                 /* Someone was smoking craq if we got here, and we're all gonna die. */
1157                                                         break;
1158                                                 }
1159                                         }
1160                                         catch (CoreException &e)
1161                                         {
1162                                                 ServerInstance->Threads->Unlock();
1163                                                 throw e;
1164                                         }
1165                                         ServerInstance->Threads->Unlock();
1166                                 }
1167                                 MultiValues[Index].validation_function(this, MultiValues[Index].tag, (char**)MultiValues[Index].items, vl, MultiValues[Index].datatype);
1168                         }
1169                         MultiValues[Index].finish_function(this, MultiValues[Index].tag);
1170                 }
1171
1172                 /* Finalise the limits, increment them all by one so that we can just put assign(str, 0, val)
1173                  * rather than assign(str, 0, val + 1)
1174                  */
1175                 Limits.Finalise();
1176
1177         }
1178
1179         catch (CoreException &ce)
1180         {
1181                 ReportConfigError(ce.GetReason(), bail, useruid);
1182                 return;
1183         }
1184
1185         ServerInstance->Threads->Lock();
1186         for (int i = 0; i < ConfValueEnum(newconfig, "type"); ++i)
1187         {
1188                 char item[MAXBUF], classn[MAXBUF], classes[MAXBUF];
1189                 std::string classname;
1190                 ConfValue(newconfig, "type", "classes", "", i, classes, MAXBUF, false);
1191                 irc::spacesepstream str(classes);
1192                 ConfValue(newconfig, "type", "name", "", i, item, MAXBUF, false);
1193                 while (str.GetToken(classname))
1194                 {
1195                         std::string lost;
1196                         bool foundclass = false;
1197                         for (int j = 0; j < ConfValueEnum(newconfig, "class"); ++j)
1198                         {
1199                                 ConfValue(newconfig, "class", "name", "", j, classn, MAXBUF, false);
1200                                 if (!strcmp(classn, classname.c_str()))
1201                                 {
1202                                         foundclass = true;
1203                                         break;
1204                                 }
1205                         }
1206                         if (!foundclass)
1207                         {
1208                                 if (!useruid.empty())
1209                                 {
1210                                         User* user = ServerInstance->FindNick(useruid);
1211                                         if (user)
1212                                                 user->WriteServ("NOTICE %s :*** Warning: Oper type '%s' has a missing class named '%s', this does nothing!", user->nick.c_str(), item, classname.c_str());
1213                                 }
1214                                 else
1215                                 {
1216                                         if (bail)
1217                                                 printf("Warning: Oper type '%s' has a missing class named '%s', this does nothing!\n", item, classname.c_str());
1218                                         else
1219                                                 ServerInstance->SNO->WriteToSnoMask('A', "Warning: Oper type '%s' has a missing class named '%s', this does nothing!", item, classname.c_str());
1220                                 }
1221                         }
1222                 }
1223         }
1224
1225         /* If we succeeded, set the ircd config to the new one */
1226         this->config_data = newconfig;
1227
1228         ServerInstance->Threads->Unlock();
1229
1230         // write once here, to try it out and make sure its ok
1231         ServerInstance->WritePID(this->PID);
1232
1233         /* Switch over logfiles */
1234         ServerInstance->Logs->CloseLogs();
1235         ServerInstance->Logs->OpenFileLogs();
1236
1237         ServerInstance->Logs->Log("CONFIG", DEFAULT, "Done reading configuration file.");
1238
1239         /* If we're rehashing, let's load any new modules, and unload old ones
1240          */
1241         if (!bail)
1242         {
1243                 int found_ports = 0;
1244                 FailedPortList pl;
1245                 ServerInstance->BindPorts(false, found_ports, pl);
1246
1247                 if (pl.size() && !useruid.empty())
1248                 {
1249                         ServerInstance->Threads->Lock();
1250                         User* user = ServerInstance->FindNick(useruid);
1251                         if (user)
1252                         {
1253                                 user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str());
1254                                 user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str());
1255                                 int j = 1;
1256                                 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
1257                                 {
1258                                         user->WriteServ("NOTICE %s :*** %d.   Address: %s        Reason: %s", user->nick.c_str(), j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
1259                                 }
1260                         }
1261                         ServerInstance->Threads->Unlock();
1262                 }
1263
1264                 ServerInstance->Threads->Lock();
1265                 if (!removed_modules.empty())
1266                 {
1267                         for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
1268                         {
1269                                 if (ServerInstance->Modules->Unload(removing->c_str()))
1270                                 {
1271                                         ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
1272
1273                                         if (!useruid.empty())
1274                                         {
1275                                                 User* user = ServerInstance->FindNick(useruid);
1276                                                 if (user)
1277                                                         user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
1278                                         }
1279                                         else
1280                                                 ServerInstance->SNO->WriteToSnoMask('A', "Module %s successfully unloaded.", removing->c_str());
1281
1282                                         rem++;
1283                                 }
1284                                 else
1285                                 {
1286                                         if (!useruid.empty())
1287                                         {
1288                                                 User* user = ServerInstance->FindNick(useruid);
1289                                                 if (user)
1290                                                         user->WriteNumeric(ERR_CANTUNLOADMODULE, "%s %s :Failed to unload module %s: %s",user->nick.c_str(), removing->c_str(), removing->c_str(), ServerInstance->Modules->LastError().c_str());
1291                                         }
1292                                         else
1293                                                  ServerInstance->SNO->WriteToSnoMask('A', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str());
1294                                 }
1295                         }
1296                 }
1297
1298                 if (!added_modules.empty())
1299                 {
1300                         for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
1301                         {
1302                                 if (ServerInstance->Modules->Load(adding->c_str()))
1303                                 {
1304                                         ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH LOADED MODULE: %s",adding->c_str());
1305                                         if (!useruid.empty())
1306                                         {
1307                                                 User* user = ServerInstance->FindNick(useruid);
1308                                                 if (user)
1309                                                         user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
1310                                         }
1311                                         else
1312                                                 ServerInstance->SNO->WriteToSnoMask('A', "Module %s successfully loaded.", adding->c_str());
1313
1314                                         add++;
1315                                 }
1316                                 else
1317                                 {
1318                                         if (!useruid.empty())
1319                                         {
1320                                                 User* user = ServerInstance->FindNick(useruid);
1321                                                 if (user)
1322                                                         user->WriteNumeric(ERR_CANTLOADMODULE, "%s %s :Failed to load module %s: %s",user->nick.c_str(), adding->c_str(), adding->c_str(), ServerInstance->Modules->LastError().c_str());
1323                                         }
1324                                         else
1325                                                 ServerInstance->SNO->WriteToSnoMask('A', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str());
1326                                 }
1327                         }
1328                 }
1329
1330                 ServerInstance->Logs->Log("CONFIG", DEFAULT, "Successfully unloaded %lu of %lu modules and loaded %lu of %lu modules.",(unsigned long)rem,(unsigned long)removed_modules.size(),(unsigned long)add,(unsigned long)added_modules.size());
1331
1332                 ServerInstance->Threads->Unlock();
1333
1334         }
1335
1336         if (bail)
1337         {
1338                 /** Note: This is safe, the method checks for user == NULL */
1339                 ServerInstance->Threads->Lock();
1340                 User* user = NULL;
1341                 if (!useruid.empty())
1342                         user = ServerInstance->FindNick(useruid);
1343                 ServerInstance->Parser->SetupCommandTable(user);
1344                 ServerInstance->Threads->Unlock();
1345         }
1346         else
1347         {
1348                 if (!useruid.empty())
1349                 {
1350                         User* user = ServerInstance->FindNick(useruid);
1351                         if (user)
1352                                 user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str());
1353                 }
1354                 else
1355                         ServerInstance->SNO->WriteToSnoMask('A', "*** Successfully rehashed server.");
1356         }
1357
1358 }
1359
1360
1361 bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const char* filename, std::ostringstream &errorstream)
1362 {
1363         std::string line;
1364         char ch;
1365         long linenumber = 1;
1366         long last_successful_parse = 1;
1367         bool in_tag;
1368         bool in_quote;
1369         bool in_comment;
1370         int character_count = 0;
1371
1372         in_tag = false;
1373         in_quote = false;
1374         in_comment = false;
1375
1376         ServerInstance->Logs->Log("CONFIG", DEBUG, "Reading %s", filename);
1377
1378         /* Check if the file open failed first */
1379         if (!conf)
1380         {
1381                 errorstream << "LoadConf: Couldn't open config file: " << filename << std::endl;
1382                 return false;
1383         }
1384
1385         for (unsigned int t = 0; t < include_stack.size(); t++)
1386         {
1387                 if (std::string(filename) == include_stack[t])
1388                 {
1389                         errorstream << "File " << filename << " is included recursively (looped inclusion)." << std::endl;
1390                         return false;
1391                 }
1392         }
1393
1394         /* It's not already included, add it to the list of files we've loaded */
1395         include_stack.push_back(filename);
1396
1397         /* Start reading characters... */
1398         while ((ch = fgetc(conf)) != EOF)
1399         {
1400                 /*
1401                  * Fix for moronic windows issue spotted by Adremelech.
1402                  * Some windows editors save text files as utf-16, which is
1403                  * a total pain in the ass to parse. Users should save in the
1404                  * right config format! If we ever see a file where the first
1405                  * byte is 0xFF or 0xFE, or the second is 0xFF or 0xFE, then
1406                  * this is most likely a utf-16 file. Bail out and insult user.
1407                  */
1408                 if ((character_count++ < 2) && (ch == '\xFF' || ch == '\xFE'))
1409                 {
1410                         errorstream << "File " << filename << " cannot be read, as it is encoded in braindead UTF-16. Save your file as plain ASCII!" << std::endl;
1411                         return false;
1412                 }
1413
1414                 /*
1415                  * Here we try and get individual tags on separate lines,
1416                  * this would be so easy if we just made people format
1417                  * their config files like that, but they don't so...
1418                  * We check for a '<' and then know the line is over when
1419                  * we get a '>' not inside quotes. If we find two '<' and
1420                  * no '>' then die with an error.
1421                  */
1422
1423                 if ((ch == '#') && !in_quote)
1424                         in_comment = true;
1425
1426                 switch (ch)
1427                 {
1428                         case '\n':
1429                                 if (in_quote)
1430                                         line += '\n';
1431                                 linenumber++;
1432                         case '\r':
1433                                 if (!in_quote)
1434                                         in_comment = false;
1435                         case '\0':
1436                                 continue;
1437                         case '\t':
1438                                 ch = ' ';
1439                 }
1440
1441                 if(in_comment)
1442                         continue;
1443
1444                 /* XXX: Added by Brain, May 1st 2006 - Escaping of characters.
1445                  * Note that this WILL NOT usually allow insertion of newlines,
1446                  * because a newline is two characters long. Use it primarily to
1447                  * insert the " symbol.
1448                  *
1449                  * Note that this also involves a further check when parsing the line,
1450                  * which can be found below.
1451                  */
1452                 if ((ch == '\\') && (in_quote) && (in_tag))
1453                 {
1454                         line += ch;
1455                         char real_character;
1456                         if (!feof(conf))
1457                         {
1458                                 real_character = fgetc(conf);
1459                                 if (real_character == 'n')
1460                                         real_character = '\n';
1461                                 line += real_character;
1462                                 continue;
1463                         }
1464                         else
1465                         {
1466                                 errorstream << "End of file after a \\, what did you want to escape?: " << filename << ":" << linenumber << std::endl;
1467                                 return false;
1468                         }
1469                 }
1470
1471                 if (ch != '\r')
1472                         line += ch;
1473
1474                 if ((ch != '<') && (!in_tag) && (!in_comment) && (ch > ' ') && (ch != 9))
1475                 {
1476                         errorstream << "You have stray characters beyond the tag which starts at " << filename << ":" << last_successful_parse << std::endl;
1477                         return false;
1478                 }
1479
1480                 if (ch == '<')
1481                 {
1482                         if (in_tag)
1483                         {
1484                                 if (!in_quote)
1485                                 {
1486                                         errorstream << "The tag at location " << filename << ":" << last_successful_parse << " was valid, but there is an error in the tag which comes after it. You are possibly missing a \" or >. Please check this." << std::endl;
1487                                         return false;
1488                                 }
1489                         }
1490                         else
1491                         {
1492                                 if (in_quote)
1493                                 {
1494                                         errorstream << "Parser error: Inside a quote but not within the last valid tag, which was opened at: " << filename << ":" << last_successful_parse << std::endl;
1495                                         return false;
1496                                 }
1497                                 else
1498                                 {
1499                                         // errorstream << "Opening new config tag on line " << linenumber << std::endl;
1500                                         in_tag = true;
1501                                 }
1502                         }
1503                 }
1504                 else if (ch == '"')
1505                 {
1506                         if (in_tag)
1507                         {
1508                                 if (in_quote)
1509                                 {
1510                                         // errorstream << "Closing quote in config tag on line " << linenumber << std::endl;
1511                                         in_quote = false;
1512                                 }
1513                                 else
1514                                 {
1515                                         // errorstream << "Opening quote in config tag on line " << linenumber << std::endl;
1516                                         in_quote = true;
1517                                 }
1518                         }
1519                         else
1520                         {
1521                                 if (in_quote)
1522                                 {
1523                                         errorstream << "The tag immediately after the one at " << filename << ":" << last_successful_parse << " has a missing closing \" symbol. Please check this." << std::endl;
1524                                 }
1525                                 else
1526                                 {
1527                                         errorstream << "You have opened a quote (\") beyond the tag at " << filename << ":" << last_successful_parse << " without opening a new tag. Please check this." << std::endl;
1528                                 }
1529                         }
1530                 }
1531                 else if (ch == '>')
1532                 {
1533                         if (!in_quote)
1534                         {
1535                                 if (in_tag)
1536                                 {
1537                                         // errorstream << "Closing config tag on line " << linenumber << std::endl;
1538                                         in_tag = false;
1539         
1540                                         /*
1541                                          * If this finds an <include> then ParseLine can simply call
1542                                          * LoadConf() and load the included config into the same ConfigDataHash
1543                                          */
1544                                         long bl = linenumber;
1545                                         if (!this->ParseLine(target, filename, line, linenumber, errorstream))
1546                                                 return false;
1547                                         last_successful_parse = linenumber;
1548
1549                                         linenumber = bl;
1550         
1551                                         line.clear();
1552                                 }
1553                                 else
1554                                 {
1555                                         errorstream << "You forgot to close the tag which comes immediately after the one at " << filename << ":" << last_successful_parse << std::endl;
1556                                         return false;
1557                                 }
1558                         }
1559                 }
1560         }
1561
1562         /* Fix for bug #392 - if we reach the end of a file and we are still in a quote or comment, most likely the user fucked up */
1563         if (in_comment || in_quote)
1564         {
1565                 errorstream << "Reached end of file whilst still inside a quoted section or tag. This is most likely an error or there \
1566                         is a newline missing from the end of the file: " << filename << ":" << linenumber << std::endl;
1567         }
1568
1569         return true;
1570 }
1571
1572
1573 bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const std::string &filename, std::ostringstream &errorstream)
1574 {
1575         return this->LoadConf(target, conf, filename.c_str(), errorstream);
1576 }
1577
1578 bool ServerConfig::ParseLine(ConfigDataHash &target, const std::string &filename, std::string &line, long &linenumber, std::ostringstream &errorstream)
1579 {
1580         std::string tagname;
1581         std::string current_key;
1582         std::string current_value;
1583         KeyValList results;
1584         char last_char = 0;
1585         bool got_name;
1586         bool got_key;
1587         bool in_quote;
1588
1589         got_name = got_key = in_quote = false;
1590
1591         for(std::string::iterator c = line.begin(); c != line.end(); c++)
1592         {
1593                 if (!got_name)
1594                 {
1595                         /* We don't know the tag name yet. */
1596
1597                         if (*c != ' ')
1598                         {
1599                                 if (*c != '<')
1600                                 {
1601                                         if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <='Z') || (*c >= '0' && *c <= '9') || *c == '_')
1602                                                 tagname += *c;
1603                                         else
1604                                         {
1605                                                 errorstream << "Invalid character in value name of tag: '" << *c << "' in value '" << tagname << "' in filename: " << filename << ":" << linenumber << std::endl;
1606                                                 return false;
1607                                         }
1608                                 }
1609                         }
1610                         else
1611                         {
1612                                 /* We got to a space, we should have the tagname now. */
1613                                 if(tagname.length())
1614                                 {
1615                                         got_name = true;
1616                                 }
1617                         }
1618                 }
1619                 else
1620                 {
1621                         /* We have the tag name */
1622                         if (!got_key)
1623                         {
1624                                 /* We're still reading the key name */
1625                                 if ((*c != '=') && (*c != '>'))
1626                                 {
1627                                         if (*c != ' ')
1628                                         {
1629                                                 if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <='Z') || (*c >= '0' && *c <= '9') || *c == '_')
1630                                                         current_key += *c;
1631                                                 else
1632                                                 {
1633                                                         errorstream << "Invalid character in key: '" << *c << "' in key '" << current_key << "' in filename: " << filename << ":" << linenumber << std::endl;
1634                                                         return false;
1635                                                 }
1636                                         }
1637                                 }
1638                                 else
1639                                 {
1640                                         /* We got an '=', end of the key name. */
1641                                         got_key = true;
1642                                 }
1643                         }
1644                         else
1645                         {
1646                                 /* We have the key name, now we're looking for quotes and the value */
1647
1648                                 /* Correctly handle escaped characters here.
1649                                  * See the XXX'ed section above.
1650                                  */
1651                                 if ((*c == '\\') && (in_quote))
1652                                 {
1653                                         c++;
1654                                         if (*c == 'n')
1655                                                 current_value += '\n';
1656                                         else
1657                                                 current_value += *c;
1658                                         continue;
1659                                 }
1660                                 else if ((*c == '\\') && (!in_quote))
1661                                 {
1662                                         errorstream << "You can't have an escape sequence outside of a quoted section: " << filename << ":" << linenumber << std::endl;
1663                                         return false;
1664                                 }
1665                                 else if ((*c == '\n') && (in_quote))
1666                                 {
1667                                         /* Got a 'real' \n, treat it as part of the value */
1668                                         current_value += '\n';
1669                                         continue;
1670                                 }
1671                                 else if ((*c == '\r') && (in_quote))
1672                                 {
1673                                         /* Got a \r, drop it */
1674                                         continue;
1675                                 }
1676
1677                                 if (*c == '"')
1678                                 {
1679                                         if (!in_quote)
1680                                         {
1681                                                 /* We're not already in a quote. */
1682                                                 in_quote = true;
1683                                         }
1684                                         else
1685                                         {
1686                                                 /* Leaving the quotes, we have the current value */
1687                                                 results.push_back(KeyVal(current_key, current_value));
1688
1689                                                 // std::cout << "<" << tagname << ":" << current_key << "> " << current_value << std::endl;
1690
1691                                                 in_quote = false;
1692                                                 got_key = false;
1693
1694                                                 if ((tagname == "include") && (current_key == "file"))
1695                                                 {       
1696                                                         if (!this->DoInclude(target, current_value, errorstream))
1697                                                                 return false;
1698                                                 }
1699                                                 else if ((tagname == "include") && (current_key == "executable"))
1700                                                 {
1701                                                         /* Pipe an executable and use its stdout as config data */
1702                                                         if (!this->DoPipe(target, current_value, errorstream))
1703                                                                 return false;
1704                                                 }
1705
1706                                                 current_key.clear();
1707                                                 current_value.clear();
1708                                         }
1709                                 }
1710                                 else
1711                                 {
1712                                         if (in_quote)
1713                                         {
1714                                                 last_char = *c;
1715                                                 current_value += *c;
1716                                         }
1717                                 }
1718                         }
1719                 }
1720         }
1721
1722         /* Finished parsing the tag, add it to the config hash */
1723         target.insert(std::pair<std::string, KeyValList > (tagname, results));
1724
1725         return true;
1726 }
1727
1728 bool ServerConfig::DoPipe(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream)
1729 {
1730         FILE* conf = popen(file.c_str(), "r");
1731         bool ret = false;
1732
1733         if (conf)
1734         {
1735                 ret = LoadConf(target, conf, file.c_str(), errorstream);
1736                 pclose(conf);
1737         }
1738         else
1739                 errorstream << "Couldn't execute: " << file << std::endl;
1740
1741         return ret;
1742 }
1743
1744 bool ServerConfig::StartsWithWindowsDriveLetter(const std::string &path)
1745 {
1746         return (path.length() > 2 && isalpha(path[0]) && path[1] == ':');
1747 }
1748
1749 bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream)
1750 {
1751         std::string confpath;
1752         std::string newfile;
1753         std::string::size_type pos;
1754
1755         confpath = ServerInstance->ConfigFileName;
1756         newfile = file;
1757
1758         std::replace(newfile.begin(),newfile.end(),'\\','/');
1759         std::replace(confpath.begin(),confpath.end(),'\\','/');
1760
1761         if ((newfile[0] != '/') && (!StartsWithWindowsDriveLetter(newfile)))
1762         {
1763                 if((pos = confpath.rfind("/")) != std::string::npos)
1764                 {
1765                         /* Leaves us with just the path */
1766                         newfile = confpath.substr(0, pos) + std::string("/") + newfile;
1767                 }
1768                 else
1769                 {
1770                         errorstream << "Couldn't get config path from: " << ServerInstance->ConfigFileName << std::endl;
1771                         return false;
1772                 }
1773         }
1774
1775         FILE* conf = fopen(newfile.c_str(), "r");
1776         bool ret = false;
1777
1778         if (conf)
1779         {
1780                 ret = LoadConf(target, conf, newfile, errorstream);
1781                 fclose(conf);
1782         }
1783         else
1784                 errorstream << "Couldn't open config file: " << file << std::endl;
1785
1786         return ret;
1787 }
1788
1789 bool ServerConfig::ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds)
1790 {
1791         return ConfValue(target, tag, var, "", index, result, length, allow_linefeeds);
1792 }
1793
1794 bool ServerConfig::ConfValue(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index, char* result, int length, bool allow_linefeeds)
1795 {
1796         std::string value;
1797         bool r = ConfValue(target, std::string(tag), std::string(var), std::string(default_value), index, value, allow_linefeeds);
1798         strlcpy(result, value.c_str(), length);
1799         return r;
1800 }
1801
1802 bool ServerConfig::ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result, bool allow_linefeeds)
1803 {
1804         return ConfValue(target, tag, var, "", index, result, allow_linefeeds);
1805 }
1806
1807 bool ServerConfig::ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds)
1808 {
1809         ConfigDataHash::size_type pos = index;
1810         if (pos < target.count(tag))
1811         {
1812                 ConfigDataHash::iterator iter = target.find(tag);
1813
1814                 for(int i = 0; i < index; i++)
1815                         iter++;
1816
1817                 for(KeyValList::iterator j = iter->second.begin(); j != iter->second.end(); j++)
1818                 {
1819                         if(j->first == var)
1820                         {
1821                                 if ((!allow_linefeeds) && (j->second.find('\n') != std::string::npos))
1822                                 {
1823                                         ServerInstance->Logs->Log("CONFIG",DEFAULT, "Value of <" + tag + ":" + var+ "> contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces.");
1824                                         for (std::string::iterator n = j->second.begin(); n != j->second.end(); n++)
1825                                                 if (*n == '\n')
1826                                                         *n = ' ';
1827                                 }
1828                                 else
1829                                 {
1830                                         result = j->second;
1831                                         return true;
1832                                 }
1833                         }
1834                 }
1835                 if (!default_value.empty())
1836                 {
1837                         result = default_value;
1838                         return true;
1839                 }
1840         }
1841         else if (pos == 0)
1842         {
1843                 if (!default_value.empty())
1844                 {
1845                         result = default_value;
1846                         return true;
1847                 }
1848         }
1849         return false;
1850 }
1851
1852 bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result)
1853 {
1854         return ConfValueInteger(target, std::string(tag), std::string(var), "", index, result);
1855 }
1856
1857 bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index, int &result)
1858 {
1859         return ConfValueInteger(target, std::string(tag), std::string(var), std::string(default_value), index, result);
1860 }
1861
1862 bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result)
1863 {
1864         return ConfValueInteger(target, tag, var, "", index, result);
1865 }
1866
1867 bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, int &result)
1868 {
1869         std::string value;
1870         std::istringstream stream;
1871         bool r = ConfValue(target, tag, var, default_value, index, value);
1872         stream.str(value);
1873         if(!(stream >> result))
1874                 return false;
1875         else
1876         {
1877                 if (!value.empty())
1878                 {
1879                         if (value.substr(0,2) == "0x")
1880                         {
1881                                 char* endptr;
1882
1883                                 value.erase(0,2);
1884                                 result = strtol(value.c_str(), &endptr, 16);
1885
1886                                 /* No digits found */
1887                                 if (endptr == value.c_str())
1888                                         return false;
1889                         }
1890                         else
1891                         {
1892                                 char denominator = *(value.end() - 1);
1893                                 switch (toupper(denominator))
1894                                 {
1895                                         case 'K':
1896                                                 /* Kilobytes -> bytes */
1897                                                 result = result * 1024;
1898                                         break;
1899                                         case 'M':
1900                                                 /* Megabytes -> bytes */
1901                                                 result = result * 1024 * 1024;
1902                                         break;
1903                                         case 'G':
1904                                                 /* Gigabytes -> bytes */
1905                                                 result = result * 1024 * 1024 * 1024;
1906                                         break;
1907                                 }
1908                         }
1909                 }
1910         }
1911         return r;
1912 }
1913
1914
1915 bool ServerConfig::ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index)
1916 {
1917         return ConfValueBool(target, std::string(tag), std::string(var), "", index);
1918 }
1919
1920 bool ServerConfig::ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index)
1921 {
1922         return ConfValueBool(target, std::string(tag), std::string(var), std::string(default_value), index);
1923 }
1924
1925 bool ServerConfig::ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index)
1926 {
1927         return ConfValueBool(target, tag, var, "", index);
1928 }
1929
1930 bool ServerConfig::ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index)
1931 {
1932         std::string result;
1933         if(!ConfValue(target, tag, var, default_value, index, result))
1934                 return false;
1935
1936         return ((result == "yes") || (result == "true") || (result == "1"));
1937 }
1938
1939 int ServerConfig::ConfValueEnum(ConfigDataHash &target, const char* tag)
1940 {
1941         return target.count(tag);
1942 }
1943
1944 int ServerConfig::ConfValueEnum(ConfigDataHash &target, const std::string &tag)
1945 {
1946         return target.count(tag);
1947 }
1948
1949 int ServerConfig::ConfVarEnum(ConfigDataHash &target, const char* tag, int index)
1950 {
1951         return ConfVarEnum(target, std::string(tag), index);
1952 }
1953
1954 int ServerConfig::ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index)
1955 {
1956         ConfigDataHash::size_type pos = index;
1957
1958         if (pos < target.count(tag))
1959         {
1960                 ConfigDataHash::const_iterator iter = target.find(tag);
1961
1962                 for(int i = 0; i < index; i++)
1963                         iter++;
1964
1965                 return iter->second.size();
1966         }
1967
1968         return 0;
1969 }
1970
1971 /** Read the contents of a file located by `fname' into a file_cache pointed at by `F'.
1972  */
1973 bool ServerConfig::ReadFile(file_cache &F, const char* fname)
1974 {
1975         if (!fname || !*fname)
1976                 return false;
1977
1978         FILE* file = NULL;
1979         char linebuf[MAXBUF];
1980
1981         F.clear();
1982
1983         if ((*fname != '/') && (*fname != '\\') && (!StartsWithWindowsDriveLetter(fname)))
1984         {
1985                 std::string::size_type pos;
1986                 std::string confpath = ServerInstance->ConfigFileName;
1987                 std::string newfile = fname;
1988
1989                 if (((pos = confpath.rfind("/"))) != std::string::npos)
1990                         newfile = confpath.substr(0, pos) + std::string("/") + fname;
1991                 else if (((pos = confpath.rfind("\\"))) != std::string::npos)
1992                         newfile = confpath.substr(0, pos) + std::string("\\") + fname;
1993
1994                 ServerInstance->Logs->Log("config", DEBUG, "Filename: %s", newfile.c_str());
1995
1996                 if (!FileExists(newfile.c_str()))
1997                         return false;
1998                 file =  fopen(newfile.c_str(), "r");
1999         }
2000         else
2001         {
2002                 if (!FileExists(fname))
2003                         return false;
2004                 file =  fopen(fname, "r");
2005         }
2006
2007         if (file)
2008         {
2009                 while (!feof(file))
2010                 {
2011                         if (fgets(linebuf, sizeof(linebuf), file))
2012                                 linebuf[strlen(linebuf)-1] = 0;
2013                         else
2014                                 *linebuf = 0;
2015
2016                         F.push_back(*linebuf ? linebuf : " ");
2017                 }
2018
2019                 fclose(file);
2020         }
2021         else
2022                 return false;
2023
2024         return true;
2025 }
2026
2027 bool ServerConfig::FileExists(const char* file)
2028 {
2029         struct stat sb;
2030         if (stat(file, &sb) == -1)
2031                 return false;
2032
2033         if ((sb.st_mode & S_IFDIR) > 0)
2034                 return false;
2035              
2036         FILE *input;
2037         if ((input = fopen (file, "r")) == NULL)
2038                 return false;
2039         else
2040         {
2041                 fclose(input);
2042                 return true;
2043         }
2044 }
2045
2046 char* ServerConfig::CleanFilename(char* name)
2047 {
2048         char* p = name + strlen(name);
2049         while ((p != name) && (*p != '/') && (*p != '\\')) p--;
2050         return (p != name ? ++p : p);
2051 }
2052
2053
2054 bool ServerConfig::DirValid(const char* dirandfile)
2055 {
2056 #ifdef WINDOWS
2057         return true;
2058 #else
2059
2060         char work[1024];
2061         char buffer[1024];
2062         char otherdir[1024];
2063         int p;
2064
2065         strlcpy(work, dirandfile, 1024);
2066         p = strlen(work);
2067
2068         // we just want the dir
2069         while (*work)
2070         {
2071                 if (work[p] == '/')
2072                 {
2073                         work[p] = '\0';
2074                         break;
2075                 }
2076
2077                 work[p--] = '\0';
2078         }
2079
2080         // Get the current working directory
2081         if (getcwd(buffer, 1024 ) == NULL )
2082                 return false;
2083
2084         if (chdir(work) == -1)
2085                 return false;
2086
2087         if (getcwd(otherdir, 1024 ) == NULL )
2088                 return false;
2089
2090         if (chdir(buffer) == -1)
2091                 return false;
2092
2093         size_t t = strlen(work);
2094
2095         if (strlen(otherdir) >= t)
2096         {
2097                 otherdir[t] = '\0';
2098                 if (!strcmp(otherdir,work))
2099                 {
2100                         return true;
2101                 }
2102
2103                 return false;
2104         }
2105         else
2106         {
2107                 return false;
2108         }
2109 #endif
2110 }
2111
2112 std::string ServerConfig::GetFullProgDir()
2113 {
2114         char buffer[PATH_MAX];
2115 #ifdef WINDOWS
2116         /* Windows has specific api calls to get the exe path that never fail.
2117          * For once, windows has something of use, compared to the POSIX code
2118          * for this, this is positively neato.
2119          */
2120         if (GetModuleFileName(NULL, buffer, MAX_PATH))
2121         {
2122                 std::string fullpath = buffer;
2123                 std::string::size_type n = fullpath.rfind("\\inspircd.exe");
2124                 return std::string(fullpath, 0, n);
2125         }
2126 #else
2127         // Get the current working directory
2128         if (getcwd(buffer, PATH_MAX))
2129         {
2130                 std::string remainder = this->argv[0];
2131
2132                 /* Does argv[0] start with /? its a full path, use it */
2133                 if (remainder[0] == '/')
2134                 {
2135                         std::string::size_type n = remainder.rfind("/inspircd");
2136                         return std::string(remainder, 0, n);
2137                 }
2138
2139                 std::string fullpath = std::string(buffer) + "/" + remainder;
2140                 std::string::size_type n = fullpath.rfind("/inspircd");
2141                 return std::string(fullpath, 0, n);
2142         }
2143 #endif
2144         return "/";
2145 }
2146
2147 InspIRCd* ServerConfig::GetInstance()
2148 {
2149         return ServerInstance;
2150 }
2151
2152 std::string ServerConfig::GetSID()
2153 {
2154         return sid;
2155 }
2156
2157 ValueItem::ValueItem(int value)
2158 {
2159         std::stringstream n;
2160         n << value;
2161         v = n.str();
2162 }
2163
2164 ValueItem::ValueItem(bool value)
2165 {
2166         std::stringstream n;
2167         n << value;
2168         v = n.str();
2169 }
2170
2171 ValueItem::ValueItem(const char* value)
2172 {
2173         v = value;
2174 }
2175
2176 void ValueItem::Set(const char* value)
2177 {
2178         v = value;
2179 }
2180
2181 void ValueItem::Set(int value)
2182 {
2183         std::stringstream n;
2184         n << value;
2185         v = n.str();
2186 }
2187
2188 int ValueItem::GetInteger()
2189 {
2190         if (v.empty())
2191                 return 0;
2192         return atoi(v.c_str());
2193 }
2194
2195 char* ValueItem::GetString()
2196 {
2197         return (char*)v.c_str();
2198 }
2199
2200 bool ValueItem::GetBool()
2201 {
2202         return (GetInteger() || v == "yes" || v == "true");
2203 }
2204
2205
2206
2207
2208 /*
2209  * XXX should this be in a class? -- w00t
2210  */
2211 bool InitTypes(ServerConfig* conf, const char*)
2212 {
2213         if (conf->opertypes.size())
2214         {
2215                 for (opertype_t::iterator n = conf->opertypes.begin(); n != conf->opertypes.end(); n++)
2216                 {
2217                         if (n->second)
2218                                 delete[] n->second;
2219                 }
2220         }
2221
2222         conf->opertypes.clear();
2223         return true;
2224 }
2225
2226 /*
2227  * XXX should this be in a class? -- w00t
2228  */
2229 bool InitClasses(ServerConfig* conf, const char*)
2230 {
2231         if (conf->operclass.size())
2232         {
2233                 for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++)
2234                 {
2235                         if (n->second.commandlist)
2236                                 delete[] n->second.commandlist;
2237                         if (n->second.cmodelist)
2238                                 delete[] n->second.cmodelist;
2239                         if (n->second.umodelist)
2240                                 delete[] n->second.umodelist;
2241                 }
2242         }
2243
2244         conf->operclass.clear();
2245         return true;
2246 }
2247
2248 /*
2249  * XXX should this be in a class? -- w00t
2250  */
2251 bool DoType(ServerConfig* conf, const char*, char**, ValueList &values, int*)
2252 {
2253         const char* TypeName = values[0].GetString();
2254         const char* Classes = values[1].GetString();
2255
2256         conf->opertypes[TypeName] = strnewdup(Classes);
2257         return true;
2258 }
2259
2260 /*
2261  * XXX should this be in a class? -- w00t
2262  */
2263 bool DoClass(ServerConfig* conf, const char* tag, char**, ValueList &values, int*)
2264 {
2265         const char* ClassName = values[0].GetString();
2266         const char* CommandList = values[1].GetString();
2267         const char* UModeList = values[2].GetString();
2268         const char* CModeList = values[3].GetString();
2269
2270         for (const char* c = UModeList; *c; ++c)
2271         {
2272                 if ((*c < 'A' || *c > 'z') && *c != '*')
2273                 {
2274                         throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in <class:usermodes>");
2275                 }
2276         }
2277         for (const char* c = CModeList; *c; ++c)
2278         {
2279                 if ((*c < 'A' || *c > 'z') && *c != '*')
2280                 {
2281                         throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in <class:chanmodes>");
2282                 }
2283         }
2284
2285         conf->operclass[ClassName].commandlist = strnewdup(CommandList);
2286         conf->operclass[ClassName].umodelist = strnewdup(UModeList);
2287         conf->operclass[ClassName].cmodelist = strnewdup(CModeList);
2288         return true;
2289 }
2290
2291 /*
2292  * XXX should this be in a class? -- w00t
2293  */
2294 bool DoneClassesAndTypes(ServerConfig*, const char*)
2295 {
2296         return true;
2297 }
2298
2299
2300
2301 bool InitXLine(ServerConfig* conf, const char* tag)
2302 {
2303         return true;
2304 }
2305
2306 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
2307 {
2308         const char* reason = values[0].GetString();
2309         const char* ipmask = values[1].GetString();
2310
2311         ZLine* zl = new ZLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ipmask);
2312         if (!conf->GetInstance()->XLines->AddLine(zl, NULL))
2313                 delete zl;
2314
2315         return true;
2316 }
2317
2318 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
2319 {
2320         const char* reason = values[0].GetString();
2321         const char* nick = values[1].GetString();
2322
2323         QLine* ql = new QLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, nick);
2324         if (!conf->GetInstance()->XLines->AddLine(ql, NULL))
2325                 delete ql;
2326
2327         return true;
2328 }
2329
2330 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
2331 {
2332         const char* reason = values[0].GetString();
2333         const char* host = values[1].GetString();
2334
2335         XLineManager* xlm = conf->GetInstance()->XLines;
2336
2337         IdentHostPair ih = xlm->IdentSplit(host);
2338
2339         KLine* kl = new KLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str());
2340         if (!xlm->AddLine(kl, NULL))
2341                 delete kl;
2342         return true;
2343 }
2344
2345 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
2346 {
2347         const char* reason = values[0].GetString();
2348         const char* host = values[1].GetString();
2349
2350         XLineManager* xlm = conf->GetInstance()->XLines;
2351
2352         IdentHostPair ih = xlm->IdentSplit(host);
2353
2354         ELine* el = new ELine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str());
2355         if (!xlm->AddLine(el, NULL))
2356                 delete el;
2357         return true;
2358 }
2359
2360 // this should probably be moved to configreader, but atm it relies on CheckELines above.
2361 bool DoneELine(ServerConfig* conf, const char* tag)
2362 {
2363         for (std::vector<User*>::const_iterator u2 = conf->GetInstance()->Users->local_users.begin(); u2 != conf->GetInstance()->Users->local_users.end(); u2++)
2364         {
2365                 User* u = (User*)(*u2);
2366                 u->exempt = false;
2367         }
2368
2369         conf->GetInstance()->XLines->CheckELines();
2370         return true;
2371 }
2372
2373 void ConfigReaderThread::Run()
2374 {
2375         ServerInstance->Config->Read(do_bail, TheUserUID);
2376         ServerInstance->Threads->Lock();
2377         this->SetExitFlag();
2378         ServerInstance->Threads->Unlock();
2379 }
2380