diff options
author | Attila Molnar <attilamolnar@hush.com> | 2013-06-05 17:52:39 -0700 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2013-06-05 17:52:39 -0700 |
commit | f00ac52c5d593fcb761fc316b2582bb06158035c (patch) | |
tree | bec88a8a69c4a912606636c9df6283c154962fef /src/modules | |
parent | d9d99cd02dadf34bfcc220734ba0c422f0acb3e6 (diff) | |
parent | 5d0b2b7cfccf057e7abab94c41065f94420899cd (diff) |
Merge pull request #544 from SaberUK/master+kill-maxbuf
Purge MAXBUF in favour of a configuration option.
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/extra/m_ldapauth.cpp | 2 | ||||
-rw-r--r-- | src/modules/extra/m_mssql.cpp | 4 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_alias.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_blockcaps.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_check.cpp | 11 | ||||
-rw-r--r-- | src/modules/m_ident.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_messageflood.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_permchannels.cpp | 74 | ||||
-rw-r--r-- | src/modules/m_spanningtree/netburst.cpp | 70 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_xline_db.cpp | 78 |
12 files changed, 94 insertions, 161 deletions
diff --git a/src/modules/extra/m_ldapauth.cpp b/src/modules/extra/m_ldapauth.cpp index 2d1551b43..0a0698fc2 100644 --- a/src/modules/extra/m_ldapauth.cpp +++ b/src/modules/extra/m_ldapauth.cpp @@ -212,7 +212,7 @@ public: std::string> &replacements) { std::string result; - result.reserve(MAXBUF); + result.reserve(text.length()); for (unsigned int i = 0; i < text.length(); ++i) { char c = text[i]; diff --git a/src/modules/extra/m_mssql.cpp b/src/modules/extra/m_mssql.cpp index 244aa0922..9d9622fde 100644 --- a/src/modules/extra/m_mssql.cpp +++ b/src/modules/extra/m_mssql.cpp @@ -472,8 +472,8 @@ class SQLConn : public classbase if (sock->res_info->row_count > 0) { int cols = sock->res_info->num_cols; - char** name = new char*[MAXBUF]; - char** data = new char*[MAXBUF]; + char** name = new char*[512]; + char** data = new char*[512]; for (int j=0; j<cols; j++) { TDSCOLUMN* col = sock->current_results->columns[j]; diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index 8faee2da7..f9fddd5a1 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -803,8 +803,8 @@ class ModuleSSLGnuTLS : public Module int ret; unsigned int cert_list_size; gnutls_x509_crt_t cert; - char name[MAXBUF]; - unsigned char digest[MAXBUF]; + char name[512]; + unsigned char digest[512]; size_t digest_size = sizeof(digest); size_t name_size = sizeof(name); ssl_cert* certinfo = new ssl_cert; diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 118cedeea..7343dd21b 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -309,7 +309,7 @@ class ModuleAlias : public Module void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line) { std::string result; - result.reserve(MAXBUF); + result.reserve(newline.length()); for (unsigned int i = 0; i < newline.length(); i++) { char c = newline[i]; diff --git a/src/modules/m_blockcaps.cpp b/src/modules/m_blockcaps.cpp index 0e1fa945f..c13549db8 100644 --- a/src/modules/m_blockcaps.cpp +++ b/src/modules/m_blockcaps.cpp @@ -119,7 +119,7 @@ public: ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<blockcaps:percent> out of range, setting to default of 100."); percent = 100; } - if (minlen < 1 || minlen > MAXBUF-1) + if (minlen < 1 || minlen > ServerInstance->Config->Limits.MaxLine) { ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1."); minlen = 1; diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index fda211cf8..734089c5b 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -194,12 +194,13 @@ class CommandCheck : public Command /* note that unlike /names, we do NOT check +i vs in the channel */ for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++) { - char tmpbuf[MAXBUF]; /* - * Unlike Asuka, I define a clone as coming from the same host. --w00t - */ - snprintf(tmpbuf, MAXBUF, "%-3lu %s%s (%s@%s) %s ", ServerInstance->Users->GlobalCloneCount(i->first), targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(), i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str()); - user->SendText(checkstr + " member " + tmpbuf); + * Unlike Asuka, I define a clone as coming from the same host. --w00t + */ + user->SendText("%s member %-3lu %s%s (%s@%s) %s ", + checkstr.c_str(), ServerInstance->Users->GlobalCloneCount(i->first), + targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(), + i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str()); } // We know that the mode handler for bans is in the core and is derived from ListModeBase diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 00ff75f59..9f67a6242 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -213,8 +213,8 @@ class IdentRequestSocket : public EventHandler /* We don't really need to buffer for incomplete replies here, since IDENT replies are * extremely short - there is *no* sane reason it'd be in more than one packet */ - char ibuf[MAXBUF]; - int recvresult = ServerInstance->SE->Recv(this, ibuf, MAXBUF-1, 0); + char ibuf[256]; + int recvresult = ServerInstance->SE->Recv(this, ibuf, sizeof(ibuf)-1, 0); /* Close (but don't delete from memory) our socket * and flag as done since the ident lookup has finished diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 970087bef..65c3354a9 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -155,7 +155,7 @@ class ModuleMsgFlood : public Module std::vector<std::string> parameters; parameters.push_back(dest->name); parameters.push_back("+b"); - parameters.push_back(user->MakeWildHost()); + parameters.push_back("*!*@" + user->dhost); ServerInstance->SendGlobalMode(parameters, ServerInstance->FakeClient); } diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp index 41477ba35..ff1a35ba9 100644 --- a/src/modules/m_permchannels.cpp +++ b/src/modules/m_permchannels.cpp @@ -19,6 +19,7 @@ #include "inspircd.h" +#include <fstream> /* $ModDesc: Provides support for channel mode +P to provide permanent channels */ @@ -26,79 +27,47 @@ static std::string permchannelsconf; static bool WriteDatabase() { - FILE *f; - - if (permchannelsconf.empty()) - { - // Fake success. - return true; - } - - std::string tempname = permchannelsconf + ".tmp"; - /* * We need to perform an atomic write so as not to fuck things up. - * So, let's write to a temporary file, flush and sync the FD, then rename the file.. - * -- w00t + * So, let's write to a temporary file, flush it, then rename the file.. + * -- w00t */ - f = fopen(tempname.c_str(), "w"); - if (!f) + + // If the user has not specified a configuration file then we don't write one. + if (permchannelsconf.empty()) + return true; + + std::string permchannelsnewconf = permchannelsconf + ".tmp"; + std::ofstream stream(permchannelsnewconf.c_str()); + if (!stream.is_open()) { ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot create database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot create new db: %s (%d)", strerror(errno), errno); return false; } + + stream << "# This file is automatically generated by m_permchannels. Any changes will be overwritten." << std::endl + << "<config format=\"xml\">" << std::endl; - fputs("# Permchannels DB\n# This file is autogenerated; any changes will be overwritten!\n<config format=\"compat\">\n", f); - // Now, let's write. for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++) { Channel* chan = i->second; if (!chan->IsModeSet('P')) continue; - char line[1024]; - const char* items[] = - { - "<permchannels channel=", - chan->name.c_str(), - " topic=", - chan->topic.c_str(), - " modes=", - chan->ChanModes(true), - ">\n" - }; - - int lpos = 0, item = 0, ipos = 0; - while (lpos < 1022 && item < 7) - { - char c = items[item][ipos++]; - if (c == 0) - { - // end of this string; hop to next string, insert a quote - item++; - ipos = 0; - c = '"'; - } - else if (c == '\\' || c == '"') - { - line[lpos++] = '\\'; - } - line[lpos++] = c; - } - line[--lpos] = 0; - fputs(line, f); + stream << "<permchannels channel=\"" << ServerConfig::Escape(chan->name) + << "\" topic=\"" << ServerConfig::Escape(chan->topic) + << "\" modes=\"" << ServerConfig::Escape(chan->ChanModes(true)) + << "\">" << std::endl; } - int write_error = 0; - write_error = ferror(f); - write_error |= fclose(f); - if (write_error) + if (stream.fail()) { ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno); return false; } + stream.close(); #ifdef _WIN32 if (remove(permchannelsconf.c_str())) @@ -109,7 +78,7 @@ static bool WriteDatabase() } #endif // Use rename to move temporary to new db - this is guarenteed not to fuck up, even in case of a crash. - if (rename(tempname.c_str(), permchannelsconf.c_str()) < 0) + if (rename(permchannelsnewconf.c_str(), permchannelsconf.c_str()) < 0) { ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot move new to old database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno); @@ -120,7 +89,6 @@ static bool WriteDatabase() } - /** Handles the +P channel mode */ class PermChannel : public ModeHandler diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index 8daaefd8a..89c8046f5 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -66,18 +66,14 @@ void TreeSocket::DoBurst(TreeServer* s) */ void TreeSocket::SendServers(TreeServer* Current, TreeServer* s) { - char command[MAXBUF]; for (unsigned int q = 0; q < Current->ChildCount(); q++) { TreeServer* recursive_server = Current->GetChild(q); if (recursive_server != s) { - std::string recursive_servername = recursive_server->GetName(); - snprintf(command, MAXBUF, ":%s SERVER %s * 0 %s :%s", Current->GetID().c_str(), recursive_servername.c_str(), - recursive_server->GetID().c_str(), - recursive_server->GetDesc().c_str()); - this->WriteLine(command); - this->WriteLine(":"+recursive_server->GetID()+" VERSION :"+recursive_server->GetVersion()); + this->WriteLine(InspIRCd::Format(":%s SERVER %s * 0 %s :%s", Current->GetID().c_str(), + recursive_server->GetName().c_str(), recursive_server->GetID().c_str(), recursive_server->GetDesc().c_str())); + this->WriteLine(":" + recursive_server->GetID() + " VERSION :" + recursive_server->GetVersion()); /* down to next level */ this->SendServers(recursive_server, s); } @@ -119,8 +115,6 @@ void TreeSocket::SendFJoins(Channel* c) /** Send all XLines we know about */ void TreeSocket::SendXLines() { - char data[MAXBUF]; - std::vector<std::string> types = ServerInstance->XLines->GetAllTypes(); for (std::vector<std::string>::const_iterator it = types.begin(); it != types.end(); ++it) @@ -139,15 +133,14 @@ void TreeSocket::SendXLines() if (!i->second->IsBurstable()) break; - snprintf(data, MAXBUF, ":%s ADDLINE %s %s %s %lu %lu :%s", - ServerInstance->Config->GetSID().c_str(), - it->c_str(), - i->second->Displayable().c_str(), - i->second->source.c_str(), - (unsigned long)i->second->set_time, - (unsigned long)i->second->duration, - i->second->reason.c_str()); - this->WriteLine(data); + this->WriteLine(InspIRCd::Format(":%s ADDLINE %s %s %s %lu %lu :%s", + ServerInstance->Config->GetSID().c_str(), + it->c_str(), + i->second->Displayable().c_str(), + i->second->source.c_str(), + (unsigned long)i->second->set_time, + (unsigned long)i->second->duration, + i->second->reason.c_str())); } } } @@ -156,16 +149,15 @@ void TreeSocket::SendXLines() /** Send channel topic, modes and metadata */ void TreeSocket::SyncChannel(Channel* chan) { - char data[MAXBUF]; - SendFJoins(chan); // If the topic was ever set, send it, even if it's empty now // because a new empty topic should override an old non-empty topic if (chan->topicset != 0) { - snprintf(data,MAXBUF,":%s FTOPIC %s %lu %lu %s :%s", ServerInstance->Config->GetSID().c_str(), chan->name.c_str(), (unsigned long) chan->age, (unsigned long)chan->topicset, chan->setby.c_str(), chan->topic.c_str()); - this->WriteLine(data); + this->WriteLine(InspIRCd::Format(":%s FTOPIC %s %lu %lu %s :%s", ServerInstance->Config->GetSID().c_str(), + chan->name.c_str(), (unsigned long)chan->age, (unsigned long)chan->topicset, + chan->setby.c_str(), chan->topic.c_str())); } for (Extensible::ExtensibleStore::const_iterator i = chan->GetExtList().begin(); i != chan->GetExtList().end(); i++) @@ -182,7 +174,6 @@ void TreeSocket::SyncChannel(Channel* chan) /** send all users and their oper state/modes */ void TreeSocket::SendUsers() { - char data[MAXBUF]; for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++) { if (u->second->registered == REG_ALL) @@ -190,28 +181,27 @@ void TreeSocket::SendUsers() TreeServer* theirserver = Utils->FindServer(u->second->server); if (theirserver) { - snprintf(data,MAXBUF,":%s UID %s %lu %s %s %s %s %s %lu +%s :%s", - theirserver->GetID().c_str(), /* Prefix: SID */ - u->second->uuid.c_str(), /* 0: UUID */ - (unsigned long)u->second->age, /* 1: TS */ - u->second->nick.c_str(), /* 2: Nick */ - u->second->host.c_str(), /* 3: Displayed Host */ - u->second->dhost.c_str(), /* 4: Real host */ - u->second->ident.c_str(), /* 5: Ident */ - u->second->GetIPString().c_str(), /* 6: IP string */ - (unsigned long)u->second->signon, /* 7: Signon time for WHOWAS */ - u->second->FormatModes(true), /* 8...n: Modes and params */ - u->second->fullname.c_str()); /* size-1: GECOS */ - this->WriteLine(data); + this->WriteLine(InspIRCd::Format(":%s UID %s %lu %s %s %s %s %s %lu +%s :%s", + theirserver->GetID().c_str(), // Prefix: SID + u->second->uuid.c_str(), // 0: UUID + (unsigned long)u->second->age, // 1: TS + u->second->nick.c_str(), // 2: Nick + u->second->host.c_str(), // 3: Real host + u->second->dhost.c_str(), // 4: Display host + u->second->ident.c_str(), // 5: Ident + u->second->GetIPString().c_str(), // 6: IP address + (unsigned long)u->second->signon, // 7: Signon time + u->second->FormatModes(true), // 8...n: User modes and params + u->second->fullname.c_str())); // size-1: GECOS + if (u->second->IsOper()) { - snprintf(data,MAXBUF,":%s OPERTYPE :%s", u->second->uuid.c_str(), u->second->oper->name.c_str()); - this->WriteLine(data); + this->WriteLine(InspIRCd::Format(":%s OPERTYPE :%s", u->second->uuid.c_str(), u->second->oper->name.c_str())); } if (u->second->IsAway()) { - snprintf(data,MAXBUF,":%s AWAY %ld :%s", u->second->uuid.c_str(), (long)u->second->awaytime, u->second->awaymsg.c_str()); - this->WriteLine(data); + this->WriteLine(InspIRCd::Format(":%s AWAY %ld :%s", u->second->uuid.c_str(), (long)u->second->awaytime, + u->second->awaymsg.c_str())); } } diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 157679ed7..c469f41a2 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -197,7 +197,7 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerLis std::string SpanningTreeUtilities::ConstructLine(const std::string& prefix, const std::string& command, const parameterlist& params) { std::string FullLine; - FullLine.reserve(MAXBUF); + FullLine.reserve(1024); FullLine = ":" + prefix + " " + command; for (parameterlist::const_iterator x = params.begin(); x != params.end(); ++x) { diff --git a/src/modules/m_xline_db.cpp b/src/modules/m_xline_db.cpp index e325fc088..0b3361953 100644 --- a/src/modules/m_xline_db.cpp +++ b/src/modules/m_xline_db.cpp @@ -20,6 +20,7 @@ #include "inspircd.h" #include "xline.h" +#include <fstream> /* $ModConfig: <xlinedb filename="data/xline.db"> * Specify the filename for the xline database here*/ @@ -85,18 +86,16 @@ class ModuleXLineDB : public Module bool WriteDatabase() { - FILE *f; - /* * We need to perform an atomic write so as not to fuck things up. - * So, let's write to a temporary file, flush and sync the FD, then rename the file.. + * So, let's write to a temporary file, flush it, then rename the file.. * Technically, that means that this can block, but I have *never* seen that. - * -- w00t + * -- w00t */ ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Opening temporary database"); std::string xlinenewdbpath = xlinedbpath + ".new"; - f = fopen(xlinenewdbpath.c_str(), "w"); - if (!f) + std::ofstream stream(xlinenewdbpath.c_str()); + if (!stream.is_open()) { ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot create database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot create new db: %s (%d)", strerror(errno), errno); @@ -112,7 +111,7 @@ class ModuleXLineDB : public Module * semblance of backwards compatibility for reading on startup.. * -- w00t */ - fprintf(f, "VERSION 1\n"); + stream << "VERSION 1" << std::endl; // Now, let's write. std::vector<std::string> types = ServerInstance->XLines->GetAllTypes(); @@ -125,26 +124,21 @@ class ModuleXLineDB : public Module for (LookupIter i = lookup->begin(); i != lookup->end(); ++i) { XLine* line = i->second; - fprintf(f, "LINE %s %s %s %lu %lu :%s\n", - line->type.c_str(), - line->Displayable().c_str(), - ServerInstance->Config->ServerName.c_str(), - (unsigned long)line->set_time, - (unsigned long)line->duration, line->reason.c_str()); + stream << "LINE " << line->type << " " << line->Displayable() << " " + << ServerInstance->Config->ServerName << " " << line->set_time << " " + << line->duration << " " << line->reason << std::endl; } } ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Finished writing XLines. Checking for error.."); - int write_error = 0; - write_error = ferror(f); - write_error |= fclose(f); - if (write_error) + if (stream.fail()) { ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot write to new database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno); return false; } + stream.close(); #ifdef _WIN32 if (remove(xlinedbpath.c_str())) @@ -167,42 +161,23 @@ class ModuleXLineDB : public Module bool ReadDatabase() { - FILE *f; - char linebuf[MAXBUF]; + // If the xline database doesn't exist then we don't need to load it. + if (!ServerConfig::FileExists(xlinedbpath.c_str())) + return true; - f = fopen(xlinedbpath.c_str(), "r"); - if (!f) + std::ifstream stream(xlinedbpath.c_str()); + if (!stream.is_open()) { - if (errno == ENOENT) - { - /* xline.db doesn't exist, fake good return value (we don't care about this) */ - return true; - } - else - { - /* this might be slightly more problematic. */ - ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot read database! %s (%d)", strerror(errno), errno); - ServerInstance->SNO->WriteToSnoMask('a', "database: cannot read db: %s (%d)", strerror(errno), errno); - return false; - } + ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot read database! %s (%d)", strerror(errno), errno); + ServerInstance->SNO->WriteToSnoMask('a', "database: cannot read db: %s (%d)", strerror(errno), errno); + return false; } - - while (fgets(linebuf, MAXBUF, f)) + + std::string line; + while (std::getline(stream, line)) { - char *c = linebuf; - - while (c && *c) - { - if (*c == '\n') - { - *c = '\0'; - } - - c++; - } - // Inspired by the command parser. :) - irc::tokenstream tokens(linebuf); + irc::tokenstream tokens(line); int items = 0; std::string command_p[7]; std::string tmp; @@ -213,7 +188,7 @@ class ModuleXLineDB : public Module items++; } - ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Processing %s", linebuf); + ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Processing %s", line.c_str()); if (command_p[0] == "VERSION") { @@ -223,7 +198,7 @@ class ModuleXLineDB : public Module } else { - fclose(f); + stream.close(); ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: I got database version %s - I don't understand it", command_p[1].c_str()); ServerInstance->SNO->WriteToSnoMask('a', "database: I got a database version (%s) I don't understand", command_p[1].c_str()); return false; @@ -251,8 +226,7 @@ class ModuleXLineDB : public Module delete xl; } } - - fclose(f); + stream.close(); return true; } |