X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fconfigreader.cpp;h=5735b395c93217dabd0f46e58adf9eec4dfaeef0;hb=f7730d08b695019c84a0b5961d8fb6bdb67365b9;hp=8f50e0762a06cd8a0920c41c289b7e090ccc98fd;hpb=efd79c8977e51dec63d2a2c49a873cad004103ca;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/configreader.cpp b/src/configreader.cpp index 8f50e0762..5735b395c 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -21,6 +21,8 @@ /* $CopyInstall: conf/inspircd.filter.example $(CONPATH) */ /* $CopyInstall: conf/inspircd.conf.example $(CONPATH) */ /* $CopyInstall: conf/modules.conf.example $(CONPATH) */ +/* $CopyInstall: conf/opers.conf.example $(CONPATH) */ +/* $CopyInstall: conf/links.conf.example $(CONPATH) */ #include "inspircd.h" #include @@ -455,28 +457,16 @@ bool InitConnect(ServerConfig* conf, const char*) { conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Reading connect classes..."); - for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end() ; ) + /* + * Remove all connect classes.. we'll reset the pointers in user classes + * once all new classes have been read from config. + */ + while (conf->Classes.begin() != conf->Classes.end()) { - ConnectClass* c = *i; + ConnectClass *c = *conf->Classes.begin(); - /* only delete a class with refcount 0 */ - if (c->RefCount == 0) - { - conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Removing connect class, refcount is 0!"); - - /* This was causing a crash, because we'd set i to .begin() just here, but then the for loop's increment would - * set it to .begin() + 1. Which if it was already the last thing in the list, wasn't good. - * Now the increment is in the else { } below. - */ - conf->Classes.erase(i); - i = conf->Classes.begin(); // start over so we don't trample on a bad iterator - } - else - { - /* also mark all existing classes disabled, if they still exist in the conf, they will be reenabled. */ - c->SetDisabled(true); - i++; - } + delete c; + conf->Classes.erase(conf->Classes.begin()); } return true; @@ -505,27 +495,6 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*) unsigned long limit = values[15].GetInteger(); const char* hashtype = values[16].GetString(); - /* - * duplicates check: Now we don't delete all connect classes on rehash, we need to ensure we don't add dupes. - * easier said than done, but for now we'll just disallow anything with a duplicate host or name. -- w00t - */ - for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item) - { - ConnectClass* cc = *item; - if ( - ((*name && (cc->GetName() == name)) || // if the name is the same - (*allow && (cc->GetHost() == allow)) || // or the allow is the same - (*deny && (cc->GetHost() == deny))) && // or the deny is the same - (!port || (port && (cc->GetPort() == port))) // and there is no port, or there is a port and the port is the same - ) - { - /* reenable class so users can be shoved into it :P */ - cc->SetDisabled(false); - conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Not adding class, it already exists!"); - return true; - } - } - conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Adding a connect class!"); if (*parent) @@ -592,6 +561,23 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*) */ bool DoneConnect(ServerConfig *conf, const char*) { + /* + * Update connect classes on all users. + */ + for (std::vector::iterator n = conf->GetInstance()->Users->local_users.begin(); n != conf->GetInstance()->Users->local_users.end(); n++) + { + User *u = *n; + + u->SetClass(); + + /* + * Check that the user falls into a valid class block.. if they don't, + * they need to be quit, which CheckClass will do. -- w00t + */ + u->CheckClass(); + } + + conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Done adding connect classes!"); return true; } @@ -701,7 +687,7 @@ bool DoneMaxBans(ServerConfig*, const char*) return true; } -void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, User* user) +void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, const std::string &useruid) { ServerInstance->Logs->Log("CONFIG",DEFAULT, "There were errors in your configuration file: %s", errormessage.c_str()); if (bail) @@ -717,14 +703,18 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, unsigned int prefixlen; start = 0; /* ":ServerInstance->Config->ServerName NOTICE user->nick :" */ - if (user) + if (!useruid.empty()) { - prefixlen = strlen(this->ServerName) + user->nick.length() + 11; - user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick.c_str()); - while (start < errors.length()) + User* user = ServerInstance->FindNick(useruid); + if (user) { - user->WriteServ("NOTICE %s :%s",user->nick.c_str(), errors.substr(start, 510 - prefixlen).c_str()); - start += 510 - prefixlen; + prefixlen = strlen(this->ServerName) + user->nick.length() + 11; + user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick.c_str()); + while (start < errors.length()) + { + user->WriteServ("NOTICE %s :%s",user->nick.c_str(), errors.substr(start, 510 - prefixlen).c_str()); + start += 510 - prefixlen; + } } } else @@ -740,7 +730,7 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, } } -void ServerConfig::Read(bool bail, User* user) +void ServerConfig::Read(bool bail, const std::string &useruid) { int rem = 0, add = 0; /* Number of modules added, number of modules removed */ @@ -813,6 +803,9 @@ void ServerConfig::Read(bool bail, User* user) {"disabled", "usermodes", "", new ValueContainerChar (disabledumodes), DT_CHARPTR, ValidateDisabledUModes}, {"disabled", "chanmodes", "", new ValueContainerChar (disabledcmodes), DT_CHARPTR, ValidateDisabledCModes}, {"disabled", "fakenonexistant", "0", new ValueContainerBool (&this->DisabledDontExist), DT_BOOLEAN, NoValidation}, + + {"security", "runasuser", "", new ValueContainerChar(this->SetUser), DT_CHARPTR, NoValidation}, + {"security", "runasgroup", "", new ValueContainerChar(this->SetGroup), DT_CHARPTR, NoValidation}, {"security", "userstats", "", new ValueContainerChar (this->UserStats), DT_CHARPTR, NoValidation}, {"security", "customversion","", new ValueContainerChar (this->CustomVersion), DT_CHARPTR, NoValidation}, {"security", "hidesplits", "0", new ValueContainerBool (&this->HideSplits), DT_BOOLEAN, NoValidation}, @@ -923,9 +916,9 @@ void ServerConfig::Read(bool bail, User* user) InitTypes, DoType, DoneClassesAndTypes}, {"class", - {"name", "commands", "usermodes", "chanmodes", NULL}, - {"", "", "", "", NULL}, - {DT_NOSPACES, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR}, + {"name", "commands", "usermodes", "chanmodes", "privs", NULL}, + {"", "", "", "", "", NULL}, + {DT_NOSPACES, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR}, InitClasses, DoClass, DoneClassesAndTypes}, {NULL, @@ -942,7 +935,7 @@ void ServerConfig::Read(bool bail, User* user) if (!this->DoInclude(newconfig, ServerInstance->ConfigFileName, errstr)) { - ReportConfigError(errstr.str(), bail, user); + ReportConfigError(errstr.str(), bail, useruid); return; } @@ -961,8 +954,6 @@ void ServerConfig::Read(bool bail, User* user) *item = 0; if (ConfValue(newconfig, ChangedConfig[Index].tag, ChangedConfig[Index].value, "", 0, item, MAXBUF, true) || *item) throw CoreException(std::string("Your configuration contains a deprecated value: <") + ChangedConfig[Index].tag + ":" + ChangedConfig[Index].value + "> - " + ChangedConfig[Index].reason); - else - ServerInstance->Logs->Log("CONFIG",DEBUG,"Deprecated item <%s:%s> does not exist, good.", ChangedConfig[Index].tag, ChangedConfig[Index].value); } /* Read the values of all the tags which occur once or not at all, and call their callbacks. @@ -1174,7 +1165,7 @@ void ServerConfig::Read(bool bail, User* user) catch (CoreException &ce) { - ReportConfigError(ce.GetReason(), bail, user); + ReportConfigError(ce.GetReason(), bail, useruid); return; } @@ -1201,8 +1192,12 @@ void ServerConfig::Read(bool bail, User* user) } if (!foundclass) { - if (user) - 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()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + 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()); + } else { if (bail) @@ -1236,15 +1231,19 @@ void ServerConfig::Read(bool bail, User* user) FailedPortList pl; ServerInstance->BindPorts(false, found_ports, pl); - if (pl.size() && user) + if (pl.size() && !useruid.empty()) { ServerInstance->Threads->Lock(); - user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str()); - user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str()); - int j = 1; - for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++) + User* user = ServerInstance->FindNick(useruid); + if (user) { - user->WriteServ("NOTICE %s :*** %d. Address: %s Reason: %s", user->nick.c_str(), j, i->first.empty() ? "" : i->first.c_str(), i->second.c_str()); + user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str()); + user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str()); + int j = 1; + for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++) + { + user->WriteServ("NOTICE %s :*** %d. Address: %s Reason: %s", user->nick.c_str(), j, i->first.empty() ? "" : i->first.c_str(), i->second.c_str()); + } } ServerInstance->Threads->Unlock(); } @@ -1258,15 +1257,27 @@ void ServerConfig::Read(bool bail, User* user) { ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH UNLOADED MODULE: %s",removing->c_str()); - if (user) - user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str()); + } + else + ServerInstance->SNO->WriteToSnoMask('A', "Module %s successfully unloaded.", removing->c_str()); rem++; } else { - if (user) - 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()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + 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()); + } + else + ServerInstance->SNO->WriteToSnoMask('A', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str()); } } } @@ -1278,16 +1289,27 @@ void ServerConfig::Read(bool bail, User* user) if (ServerInstance->Modules->Load(adding->c_str())) { ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH LOADED MODULE: %s",adding->c_str()); - - if (user) - user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str()); + } + else + ServerInstance->SNO->WriteToSnoMask('A', "Module %s successfully loaded.", adding->c_str()); add++; } else { - if (user) - 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()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + 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()); + } + else + ServerInstance->SNO->WriteToSnoMask('A', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str()); } } } @@ -1302,13 +1324,20 @@ void ServerConfig::Read(bool bail, User* user) { /** Note: This is safe, the method checks for user == NULL */ ServerInstance->Threads->Lock(); + User* user = NULL; + if (!useruid.empty()) + user = ServerInstance->FindNick(useruid); ServerInstance->Parser->SetupCommandTable(user); ServerInstance->Threads->Unlock(); } else { - if (user) - user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str()); + } else ServerInstance->SNO->WriteToSnoMask('A', "*** Successfully rehashed server."); } @@ -2196,6 +2225,8 @@ bool InitClasses(ServerConfig* conf, const char*) delete[] n->second.cmodelist; if (n->second.umodelist) delete[] n->second.umodelist; + if (n->second.privs) + delete[] n->second.privs; } } @@ -2224,6 +2255,7 @@ bool DoClass(ServerConfig* conf, const char* tag, char**, ValueList &values, int const char* CommandList = values[1].GetString(); const char* UModeList = values[2].GetString(); const char* CModeList = values[3].GetString(); + const char *PrivsList = values[4].GetString(); for (const char* c = UModeList; *c; ++c) { @@ -2243,6 +2275,7 @@ bool DoClass(ServerConfig* conf, const char* tag, char**, ValueList &values, int conf->operclass[ClassName].commandlist = strnewdup(CommandList); conf->operclass[ClassName].umodelist = strnewdup(UModeList); conf->operclass[ClassName].cmodelist = strnewdup(CModeList); + conf->operclass[ClassName].privs = strnewdup(PrivsList); return true; } @@ -2330,8 +2363,7 @@ bool DoneELine(ServerConfig* conf, const char* tag) void ConfigReaderThread::Run() { - /* TODO: TheUser may be invalid by the time we get here! Check its validity, or pass a UID would be better */ - ServerInstance->Config->Read(do_bail, TheUser); + ServerInstance->Config->Read(do_bail, TheUserUID); ServerInstance->Threads->Lock(); this->SetExitFlag(); ServerInstance->Threads->Unlock();