bool InspIRCd::NickMatchesEveryone(const std::string &nick, User* user) { long matches = 0; ConfigTag* insane = Config->ConfValue("insane"); if (insane->getBool("nickmasks")) return false; float itrigger = insane->getFloat("trigger", 95.5); for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++) { if (InspIRCd::Match(u->second->nick, nick)) matches++; } if (!matches) return false; float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100; if (percent > itrigger) { SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a Q line mask of %s, which covers %.2f%% of the network!",user->nick.c_str(),nick.c_str(),percent); return true; } return false; }
void ReadConfig(ConfigStatus& status) override { ConfigTag* tag = ServerInstance->Config->ConfValue("rline"); MatchOnNickChange = tag->getBool("matchonnickchange"); ZlineOnMatch = tag->getBool("zlineonmatch"); std::string newrxengine = tag->getString("engine"); factory = rxfactory ? (rxfactory.operator->()) : NULL; if (newrxengine.empty()) rxfactory.SetProvider("regex"); else rxfactory.SetProvider("regex/" + newrxengine); if (!rxfactory) { if (newrxengine.empty()) ServerInstance->SNO.WriteToSnoMask('a', "WARNING: No regex engine loaded - R-line functionality disabled until this is corrected."); else ServerInstance->SNO.WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-line functionality disabled until this is corrected.", newrxengine.c_str()); ServerInstance->XLines->DelAll(f.GetType()); } else if ((!initing) && (rxfactory.operator->() != factory)) { ServerInstance->SNO.WriteToSnoMask('a', "Regex engine has changed, removing all R-lines."); ServerInstance->XLines->DelAll(f.GetType()); } initing = false; }
void OnEvent(Event& event) { std::stringstream data(""); if (event.id == "httpd_url") { ServerInstance->Logs->Log("m_http_stats", LOG_DEBUG,"Handling httpd event"); HTTPRequest* http = (HTTPRequest*)&event; if ((http->GetURI() == "/config") || (http->GetURI() == "/config/")) { data << "<html><head><title>InspIRCd Configuration</title></head><body>"; data << "<h1>InspIRCd Configuration</h1><p>"; for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x) { data << "<" << x->first << " "; ConfigTag* tag = x->second; for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++) { data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" "; } data << "><br>"; } data << "</body></html>"; /* Send the document back to m_httpd */ HTTPDocumentResponse response(this, *http, &data, 200); response.headers.SetHeader("X-Powered-By", "m_httpd_config.so"); response.headers.SetHeader("Content-Type", "text/html"); response.Send(); } } }
CmdResult CommandRules::Handle (const std::vector<std::string>& parameters, User *user) { if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName) return CMD_SUCCESS; ConfigTag* tag = NULL; if (IS_LOCAL(user)) tag = user->GetClass()->config; std::string rules_name = tag->getString("rules", "rules"); ConfigFileCache::iterator rules = ServerInstance->Config->Files.find(rules_name); if (rules == ServerInstance->Config->Files.end()) { user->SendText(":%s %03d %s :RULES file is missing.", ServerInstance->Config->ServerName.c_str(), ERR_NORULES, user->nick.c_str()); return CMD_SUCCESS; } user->SendText(":%s %03d %s :%s server rules:", ServerInstance->Config->ServerName.c_str(), RPL_RULESTART, user->nick.c_str(), ServerInstance->Config->ServerName.c_str()); for (file_cache::iterator i = rules->second.begin(); i != rules->second.end(); i++) user->SendText(":%s %03d %s :- %s", ServerInstance->Config->ServerName.c_str(), RPL_RULES, user->nick.c_str(),i->c_str()); user->SendText(":%s %03d %s :End of RULES command.", ServerInstance->Config->ServerName.c_str(), RPL_RULESEND, user->nick.c_str()); return CMD_SUCCESS; }
void SetPenalties() { ConfigTagList tags = ServerInstance->Config->ConfTags("penalty"); for (ConfigIter i = tags.first; i != tags.second; ++i) { ConfigTag* tag = i->second; std::string name = tag->getString("name"); int penalty = (int)tag->getInt("value", 1); Command* command = ServerInstance->Parser->GetHandler(name); if (command == NULL) { ServerInstance->Logs->Log("m_custompenalty", DEFAULT, "Warning: unable to find command: " + name); continue; } if (penalty < 0) { ServerInstance->Logs->Log("m_custompenalty", DEFAULT, "Warning: unable to set a negative penalty for " + name); continue; } ServerInstance->Logs->Log("m_custompenalty", DEBUG, "Setting the penalty for %s to %d", name.c_str(), penalty); command->Penalty = penalty; } }
void OnRehash(User* user) { ConfigTag* tag = ServerInstance->Config->ConfValue("timedstaticquit"); this->quitmsg = tag->getString("quitmsg", "Client Quit"); int duration = ServerInstance->Duration(tag->getString("mintime", "5m")); /* Duration is in the user-friendly format (1y2w3d4h5m6s) */ this->mintime = duration <= 0 ? 1 : duration; /* The minimum time needs to be at least 1 second */ }
void ReadConfig(ConfigStatus& status) override { ConfigTag* tag = ServerInstance->Config->ConfValue("channames"); std::string denyToken = tag->getString("denyrange"); std::string allowToken = tag->getString("allowrange"); if (!denyToken.compare(0, 2, "0-")) denyToken[0] = '1'; if (!allowToken.compare(0, 2, "0-")) allowToken[0] = '1'; allowedmap.set(); irc::portparser denyrange(denyToken, false); int denyno = -1; while (0 != (denyno = denyrange.GetToken())) allowedmap[denyno & 0xFF] = false; irc::portparser allowrange(allowToken, false); int allowno = -1; while (0 != (allowno = allowrange.GetToken())) allowedmap[allowno & 0xFF] = true; allowedmap[0x07] = false; // BEL allowedmap[0x20] = false; // ' ' allowedmap[0x2C] = false; // ',' ValidateChans(); }
void ListModeBase::DoRehash() { ConfigTagList tags = ServerInstance->Config->ConfTags(configtag); limitlist oldlimits = chanlimits; chanlimits.clear(); for (ConfigIter i = tags.first; i != tags.second; i++) { // For each <banlist> tag ConfigTag* c = i->second; ListLimit limit(c->getString("chan"), c->getInt("limit")); if (limit.mask.size() && limit.limit > 0) chanlimits.push_back(limit); } if (chanlimits.empty()) chanlimits.push_back(ListLimit("*", 64)); // Most of the time our settings are unchanged, so we can avoid iterating the chanlist if (oldlimits == chanlimits) return; for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i) { ChanData* cd = extItem.get(i->second); if (cd) cd->maxitems = -1; } }
ModResult HandleRequest(HTTPRequest* http) { std::stringstream data(""); { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event"); if ((http->GetURI() == "/config") || (http->GetURI() == "/config/")) { data << "<html><head><title>InspIRCd Configuration</title></head><body>"; data << "<h1>InspIRCd Configuration</h1><p>"; for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x) { data << "<" << x->first << " "; ConfigTag* tag = x->second; for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++) { data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" "; } data << "><br>"; } data << "</body></html>"; /* Send the document back to m_httpd */ HTTPDocumentResponse response(this, *http, &data, 200); response.headers.SetHeader("X-Powered-By", MODNAME); response.headers.SetHeader("Content-Type", "text/html"); API->SendResponse(response); return MOD_RES_DENY; // Handled } } return MOD_RES_PASSTHRU; }
void OnRehash(User* user) { ConfigTag *tag = ServerInstance->Config->ConfValue("connthrottle"); throttle_num = tag->getInt("num", 1); throttle_time = tag->getInt("time", 1); }
void OnRehash(User* user) { ConfigTag* tag = ServerInstance->Config->ConfValue("requirectcp"); ctcp = tag->getString("ctcp", "VERSION"); declined = tag->getString("declined", "You have been blocked!Please get a better client."); accepted = tag->getString("accepted", "Howdy buddy,you are authorized to use this server!"); }
void ReadConfig(ConfigStatus& status) override { ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois"); sw.SetOperOnly(tag->getBool("opersonly", true)); ShowWhoisFromOpers = tag->getBool("showfromopers", true); }
CmdResult Handle (const std::vector<std::string> ¶meters, User *user) { ConfigTagList tags = ServerInstance->Config->ConfTags("vhost"); for(ConfigIter i = tags.first; i != tags.second; ++i) { ConfigTag* tag = i->second; std::string mask = tag->getString("host"); std::string username = tag->getString("user"); std::string pass = tag->getString("pass"); std::string hash = tag->getString("hash"); if (parameters[0] == username && !ServerInstance->PassCompare(user, pass, parameters[1], hash)) { if (!mask.empty()) { user->WriteServ("NOTICE "+user->nick+" :Setting your VHost: " + mask); user->ChangeDisplayedHost(mask.c_str()); return CMD_SUCCESS; } } } user->WriteServ("NOTICE "+user->nick+" :Invalid username or password."); return CMD_FAILURE; }
void ReadConfig() { helpop_map.clear(); ConfigTagList tags = ServerInstance->Config->ConfTags("helpop"); for(ConfigIter i = tags.first; i != tags.second; ++i) { ConfigTag* tag = i->second; irc::string key = assign(tag->getString("key")); std::string value; tag->readString("value", value, true); /* Linefeeds allowed */ if (key == "index") { throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it."); } helpop_map[key] = value; } if (helpop_map.find("start") == helpop_map.end()) { // error! throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf."); } else if (helpop_map.find("nohelp") == helpop_map.end()) { // error! throw ModuleException("m_helpop: Helpop file is missing important entry 'nohelp'. Please check the example conf."); } }
void OnRehash(User* user) { ConfigTag* tag = ServerInstance->Config->ConfValue("passforward"); nickrequired = tag->getString("nick", "NickServ"); forwardmsg = tag->getString("forwardmsg", "NOTICE * :*** Sending services password as an ENCAP SASL message over the network"); forwardcmd = tag->getString("cmd", "$b64p"); }
void OnRehash(User*) { ConfigTag* tag = ServerInstance->Config->ConfValue("invisible"); hidejoin = tag->getBool("join"); hidelist = tag->getBool("list"); hidewho = tag->getBool("who"); hidemsg = tag->getBool("msg"); }
void OnRehash(User*) { ConfigTag* tag = ServerInstance->Config->ConfValue("flashpolicyd"); timeout = tag->getInt("timeout", 5); std::string file = tag->getString("file"); if (timeout == 0) timeout = 1; if (!file.empty()) { try { FileReader reader(file); policy_reply = reader.Contents(); } catch (CoreException&) { const std::string error_message = "A file was specified for FlashPD, but it could not be loaded."; ServerInstance->Logs->Log("m_flashpd", DEFAULT, error_message); ServerInstance->SNO->WriteGlobalSno('a', error_message); policy_reply.clear(); } return; } // A file was not specified. Set the default setting. // We allow access to all client ports by default std::string to_ports; for (std::vector<ListenSocket*>::const_iterator i = ServerInstance->ports.begin(); i != ServerInstance->ports.end(); ++i) { ListenSocket* ls = *i; if (ls->bind_tag->getString("type", "clients") != "clients" || ls->bind_tag->getString("ssl", "plaintext") != "plaintext") continue; to_ports += (ConvToStr(ls->bind_port) + ","); } if (to_ports.empty()) { policy_reply.clear(); return; } to_ports.erase(to_ports.size() - 1); policy_reply = "<?xml version=\"1.0\"?>\ <!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\ <cross-domain-policy>\ <site-control permitted-cross-domain-policies=\"master-only\"/>\ <allow-access-from domain=\"*\" to-ports=\"" + to_ports + "\" />\ </cross-domain-policy>"; }
void ReadConfig() { allowchans.clear(); ConfigTagList tags = ServerInstance->Config->ConfTags("allowchannel"); for(ConfigIter i = tags.first; i != tags.second; ++i) { ConfigTag* tag = i->second; std::string txt = tag->getString("name"); allowchans.insert(txt.c_str()); } }
ConfigTag* ServerConfig::ConfValue(const std::string &tag) { ConfigTagList found = config_data.equal_range(tag); if (found.first == found.second) return NULL; ConfigTag* rv = found.first->second; found.first++; if (found.first != found.second) ServerInstance->Logs->Log("CONFIG",LOG_DEFAULT, "Multiple <" + tag + "> tags found; only first will be used " "(first at " + rv->getTagLocation() + "; second at " + found.first->second->getTagLocation() + ")"); return rv; }
void OnUserConnect(LocalUser* user) { ConfigTag* tag = user->MyClass->config; std::string ident = tag->getString("forceident"); if (ServerInstance->IsIdent(ident.c_str())) { ServerInstance->Logs->Log("m_forceident", DEBUG, "Setting ident of user '%s' (%s) in class '%s' to '%s'.", user->nick.c_str(), user->uuid.c_str(), user->MyClass->name.c_str(), ident.c_str()); user->ident = ident; user->InvalidateCache(); } }
void OperInfo::init() { AllowedOperCommands.clear(); AllowedPrivs.clear(); AllowedUserModes.reset(); AllowedChanModes.reset(); AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want. for(std::vector<reference<ConfigTag> >::iterator iter = class_blocks.begin(); iter != class_blocks.end(); ++iter) { ConfigTag* tag = *iter; std::string mycmd, mypriv; /* Process commands */ irc::spacesepstream CommandList(tag->getString("commands")); while (CommandList.GetToken(mycmd)) { AllowedOperCommands.insert(mycmd); } irc::spacesepstream PrivList(tag->getString("privs")); while (PrivList.GetToken(mypriv)) { AllowedPrivs.insert(mypriv); } std::string modes = tag->getString("usermodes"); for (std::string::const_iterator c = modes.begin(); c != modes.end(); ++c) { if (*c == '*') { this->AllowedUserModes.set(); } else if (*c >= 'A' && *c <= 'z') { this->AllowedUserModes[*c - 'A'] = true; } } modes = tag->getString("chanmodes"); for (std::string::const_iterator c = modes.begin(); c != modes.end(); ++c) { if (*c == '*') { this->AllowedChanModes.set(); } else if (*c >= 'A' && *c <= 'z') { this->AllowedChanModes[*c - 'A'] = true; } } } }
ModResult OnUserRegister(LocalUser* user) { ConfigTag* tag = user->MyClass->config; if (tag->getBool("requirectcp", true)) { if (!ctcp.empty()) { user->WriteServ("PRIVMSG %s :\001%s\001", user->nick.c_str(), ctcp.c_str()); } ext.set(user, 1); } return MOD_RES_PASSTHRU; }
static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make) { ConfigTagList tags = conf->ConfTags(tag); for(ConfigIter i = tags.first; i != tags.second; ++i) { ConfigTag* ctag = i->second; std::string mask; if (!ctag->readString(key, mask)) throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation()); std::string reason = ctag->getString("reason", "<Config>"); XLine* xl = make->Generate(ServerInstance->Time(), 0, "<Config>", reason, mask); if (!ServerInstance->XLines->AddLine(xl, NULL)) delete xl; } }
void ModuleManager::LoadAll() { std::map<std::string, ServiceList> servicemap; LoadCoreModules(servicemap); ConfigTagList tags = ServerInstance->Config->ConfTags("module"); for (ConfigIter i = tags.first; i != tags.second; ++i) { ConfigTag* tag = i->second; std::string name = tag->getString("name"); this->NewServices = &servicemap[name]; std::cout << "[" << con_green << "*" << con_reset << "] Loading module:\t" << con_green << name << con_reset << std::endl; if (!this->Load(name, true)) { ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError()); std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl; ServerInstance->Exit(EXIT_STATUS_MODULE); } } ConfigStatus confstatus; for (ModuleMap::const_iterator i = Modules.begin(); i != Modules.end(); ++i) { Module* mod = i->second; try { ServerInstance->Logs->Log("MODULE", LOG_DEBUG, "Initializing %s", i->first.c_str()); AttachAll(mod); AddServices(servicemap[i->first]); mod->init(); mod->ReadConfig(confstatus); } catch (CoreException& modexcept) { LastModuleError = "Unable to initialize " + mod->ModuleSourceFile + ": " + modexcept.GetReason(); ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << LastModuleError << std::endl << std::endl; ServerInstance->Exit(EXIT_STATUS_MODULE); } } this->NewServices = NULL; if (!PrioritizeHooks()) ServerInstance->Exit(EXIT_STATUS_MODULE); }
ModResult OnUserRegister(LocalUser* user) { // Note this is their initial (unresolved) connect block ConfigTag* tag = user->MyClass->config; if (!tag->getBool("usesqlauth", true)) return MOD_RES_PASSTHRU; if (!allowpattern.empty() && InspIRCd::Match(user->nick,allowpattern)) return MOD_RES_PASSTHRU; if (pendingExt.get(user)) return MOD_RES_PASSTHRU; if (!SQL) { ServerInstance->SNO->WriteGlobalSno('a', "Forbiding connection from %s (SQL database not present)", user->GetFullRealHost().c_str()); ServerInstance->Users->QuitUser(user, killreason); return MOD_RES_PASSTHRU; } pendingExt.set(user, AUTH_STATE_BUSY); ParamM userinfo; SQL->PopulateUserInfo(user, userinfo); userinfo["pass"] = user->password; HashProvider* md5 = ServerInstance->Modules->FindDataService<HashProvider>("hash/md5"); if (md5) userinfo["md5pass"] = md5->hexsum(user->password); HashProvider* sha256 = ServerInstance->Modules->FindDataService<HashProvider>("hash/sha256"); if (sha256) userinfo["sha256pass"] = sha256->hexsum(user->password); AuthQuery* authQuery = NULL; if (usebcrypt) { authQuery = new BCryptAuthQuery(this, user->uuid, user->password, pendingExt, verbose); } else { authQuery = new AuthQuery(this, user->uuid, pendingExt, verbose); } SQL->submit(authQuery, freeformquery, userinfo); return MOD_RES_PASSTHRU; }
void OnUserConnect(LocalUser* user) { ConfigTag* tag = user->MyClass->config; std::string vhost = tag->getString("vhost"); std::string replace; if (vhost.empty()) return; replace = "$ident"; if (vhost.find(replace) != std::string::npos) { std::string ident = user->ident; if (ident[0] == '~') ident.erase(0, 1); SearchAndReplace(vhost, replace, ident); } replace = "$account"; if (vhost.find(replace) != std::string::npos) { std::string account = GetAccount(user); if (account.empty()) account = "unidentified"; SearchAndReplace(vhost, replace, account); } if (vhost.length() > 64) { ServerInstance->Logs->Log("m_conn_vhost", DEFAULT, "m_conn_vhost: vhost in connect block %s is too long", user->MyClass->name.c_str()); return; } /* from m_sethost: validate the characters */ for (std::string::const_iterator x = vhost.begin(); x != vhost.end(); x++) { if (!hostmap.test(static_cast<unsigned char>(*x))) { ServerInstance->Logs->Log("m_conn_vhost", DEFAULT, "m_conn_vhost: vhost in connect block %s has invalid characters", user->MyClass->name.c_str()); return; } } user->ChangeDisplayedHost(vhost.c_str()); }
virtual void OnRehash(User* user) { ConfigTag* tag = ServerInstance->Config->ConfValue("blockamsg"); ForgetDelay = tag->getInt("delay", -1); std::string act = tag->getString("action"); if(act == "notice") action = IBLOCK_NOTICE; else if(act == "noticeopers") action = IBLOCK_NOTICEOPERS; else if(act == "silent") action = IBLOCK_SILENT; else if(act == "kill") action = IBLOCK_KILL; else action = IBLOCK_KILLOPERS; }
void OnRehash(User* user) { ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin"); if (!np) { // This is done on module load only std::string npre = Conf->getString("prefix"); NPrefix = npre.empty() ? 0 : npre[0]; if (NPrefix && ServerInstance->Modes->FindPrefix(NPrefix)) throw ModuleException("Looks like the +Y prefix you picked for m_ojoin is already in use. Pick another."); } notice = Conf->getBool("notice", true); op = Conf->getBool("op", true); }
void OnUserInit(LocalUser *user) { ConfigTag* tag = user->MyClass->config; if (!tag->getBool("useident", true)) return; user->WriteServ("NOTICE Auth :*** Looking up your ident..."); try { IdentRequestSocket *isock = new IdentRequestSocket(IS_LOCAL(user)); ext.set(user, isock); } catch (ModuleException &e) { ServerInstance->Logs->Log("m_ident",DEBUG,"Ident exception: %s", e.GetReason()); } }
CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user) { char TheHost[MAXBUF]; char TheIP[MAXBUF]; bool match_login = false; bool match_pass = false; bool match_hosts = false; snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(),user->host.c_str()); snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(),user->GetIPString().c_str()); OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]); if (i != ServerInstance->Config->oper_blocks.end()) { OperInfo* ifo = i->second; ConfigTag* tag = ifo->oper_block; match_login = true; match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash")); match_hosts = OneOfMatches(TheHost,TheIP,tag->getString("host")); if (match_pass && match_hosts) { /* found this oper's opertype */ user->Oper(ifo); return CMD_SUCCESS; } } std::string fields; if (!match_login) fields.append("login "); if (!match_pass) fields.append("password "); if (!match_hosts) fields.append("hosts"); // tell them they suck, and lag them up to help prevent brute-force attacks user->WriteNumeric(491, "%s :Invalid oper credentials",user->nick.c_str()); user->CommandFloodPenalty += 10000; ServerInstance->SNO->WriteGlobalSno('o', "WARNING! Failed oper attempt by %s using login '%s': The following fields do not match: %s", user->GetFullRealHost().c_str(), parameters[0].c_str(), fields.c_str()); ServerInstance->Logs->Log("OPER",DEFAULT,"OPER: Failed oper attempt by %s using login '%s': The following fields did not match: %s", user->GetFullRealHost().c_str(), parameters[0].c_str(), fields.c_str()); return CMD_FAILURE; }