diff options
57 files changed, 219 insertions, 371 deletions
diff --git a/.Makefile.inc b/.Makefile.inc index c801dd068..526779d80 100644 --- a/.Makefile.inc +++ b/.Makefile.inc @@ -46,7 +46,7 @@ INSTMODE = 0755 @ENDIF @IFDEF D - CXXFLAGS += -g3 + CXXFLAGS += -g3 -Werror HEADER = debug-header @ELSE CXXFLAGS += -g1 diff --git a/include/channels.h b/include/channels.h index ec09cbbca..1ded25a73 100644 --- a/include/channels.h +++ b/include/channels.h @@ -241,7 +241,7 @@ class CoreExport Channel : public Extensible * @return The number of users left on the channel. If this is zero * when the method returns, you MUST delete the Channel immediately! */ - long ServerKickUser(User* user, const char* reason, const char* servername = NULL); + long ServerKickUser(User* user, const char* reason, const std::string& servername = ""); /** Part a user from this channel with the given reason. * If the reason field is NULL, no reason will be sent. @@ -281,13 +281,13 @@ class CoreExport Channel : public Extensible * @param text A printf-style format string which builds the output line without prefix * @param ... Zero or more POD type */ - void WriteChannelWithServ(const char* ServName, const char* text, ...) CUSTOM_PRINTF(3, 4); + void WriteChannelWithServ(const std::string& ServName, const char* text, ...) CUSTOM_PRINTF(3, 4); /** Write to a channel, from a server, using std::string for text * @param ServName Server name to prefix the line with * @param text A std::string containing the output line without prefix */ - void WriteChannelWithServ(const char* ServName, const std::string &text); + void WriteChannelWithServ(const std::string& ServName, const std::string &text); /** Write to all users on a channel except a specific user, using va_args for text. * Internally, this calls WriteAllExcept(). diff --git a/include/configreader.h b/include/configreader.h index 28138edd6..893259b7c 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -206,98 +206,98 @@ class CoreExport ServerConfig : public classbase /** Both for set(g|u)id. */ - char SetUser[MAXBUF]; - char SetGroup[MAXBUF]; + std::string SetUser; + std::string SetGroup; /** Holds the server name of the local server * as defined by the administrator. */ - char ServerName[MAXBUF]; + std::string ServerName; /** Notice to give to users when they are Xlined */ - char MoronBanner[MAXBUF]; + std::string MoronBanner; /* Holds the network name the local server * belongs to. This is an arbitary field defined * by the administrator. */ - char Network[MAXBUF]; + std::string Network; /** Holds the description of the local server * as defined by the administrator. */ - char ServerDesc[MAXBUF]; + std::string ServerDesc; /** Holds the admin's name, for output in * the /ADMIN command. */ - char AdminName[MAXBUF]; + std::string AdminName; /** Holds the email address of the admin, * for output in the /ADMIN command. */ - char AdminEmail[MAXBUF]; + std::string AdminEmail; /** Holds the admin's nickname, for output * in the /ADMIN command */ - char AdminNick[MAXBUF]; + std::string AdminNick; /** The admin-configured /DIE password */ - char diepass[MAXBUF]; + std::string diepass; /** The admin-configured /RESTART password */ - char restartpass[MAXBUF]; + std::string restartpass; /** The hash method for *BOTH* the die and restart passwords. */ - char powerhash[MAXBUF]; + std::string powerhash; /** The pathname and filename of the message of the * day file, as defined by the administrator. */ - char motd[MAXBUF]; + std::string motd; /** The pathname and filename of the rules file, * as defined by the administrator. */ - char rules[MAXBUF]; + std::string rules; /** The quit prefix in use, or an empty string */ - char PrefixQuit[MAXBUF]; + std::string PrefixQuit; /** The quit suffix in use, or an empty string */ - char SuffixQuit[MAXBUF]; + std::string SuffixQuit; /** The fixed quit message in use, or an empty string */ - char FixedQuit[MAXBUF]; + std::string FixedQuit; /** The part prefix in use, or an empty string */ - char PrefixPart[MAXBUF]; + std::string PrefixPart; /** The part suffix in use, or an empty string */ - char SuffixPart[MAXBUF]; + std::string SuffixPart; /** The fixed part message in use, or an empty string */ - char FixedPart[MAXBUF]; + std::string FixedPart; /** The last string found within a <die> tag, or * an empty string. */ - char DieValue[MAXBUF]; + std::string DieValue; /** The DNS server to use for DNS queries */ - char DNSServer[MAXBUF]; + std::string DNSServer; /** Pretend disabled commands don't exist. */ @@ -307,7 +307,7 @@ class CoreExport ServerConfig : public classbase * of commands which are disabled by the * administrator of the server for non-opers. */ - char DisabledCommands[MAXBUF]; + std::string DisabledCommands; /** This variable identifies which usermodes have been diabled. */ @@ -451,11 +451,11 @@ class CoreExport ServerConfig : public classbase /** Set to a non-empty string to obfuscate the server name of users in WHOIS */ - char HideWhoisServer[MAXBUF]; + std::string HideWhoisServer; /** Set to a non empty string to obfuscate nicknames prepended to a KILL. */ - char HideKillsServer[MAXBUF]; + std::string HideKillsServer; /** The MOTD file, cached in a file_cache type. */ @@ -487,7 +487,7 @@ class CoreExport ServerConfig : public classbase /** STATS characters in this list are available * only to operators. */ - char UserStats[MAXBUF]; + std::string UserStats; /** The path and filename of the ircd.log file */ @@ -495,11 +495,11 @@ class CoreExport ServerConfig : public classbase /** Default channel modes */ - char DefaultModes[MAXBUF]; + std::string DefaultModes; /** Custom version string, which if defined can replace the system info in VERSION. */ - char CustomVersion[MAXBUF]; + std::string CustomVersion; /** List of u-lined servers */ @@ -565,7 +565,7 @@ class CoreExport ServerConfig : public classbase * makes code simpler. 0AA, 1BB etc with letters are reserved * for services use. */ - char sid[MAXBUF]; + std::string sid; /** True if we have been told to run the testsuite from the commandline, * rather than entering the mainloop. @@ -679,7 +679,7 @@ class CoreExport ServerConfig : public classbase */ int ConfVarEnum(const std::string &tag, int index); - bool ApplyDisabledCommands(const char* data); + bool ApplyDisabledCommands(const std::string& data); /** Returns the fully qualified path to the inspircd directory * @return The full program directory @@ -795,9 +795,6 @@ template<typename T> class ValueContainer : public ValueContainerBase void Set(ServerConfig* conf, const ValueItem& item); }; -template<> void ValueContainer<char[MAXBUF]>::Set(ServerConfig* conf, ValueItem const& item); - - class ValueContainerLimit : public ValueContainerBase { size_t ServerLimits::* const vptr; @@ -826,11 +823,6 @@ typedef ValueContainer<unsigned int> ValueContainerUInt; /** A specialization of ValueContainer to hold a pointer to * a char array. */ -typedef ValueContainer<char[MAXBUF]> ValueContainerChar; - -/** A specialization of ValueContainer to hold a pointer to - * a char array. - */ typedef ValueContainer<std::string> ValueContainerString; /** A specialization of ValueContainer to hold a pointer to diff --git a/include/dns.h b/include/dns.h index 1bce4f11a..76a69b6e4 100644 --- a/include/dns.h +++ b/include/dns.h @@ -320,14 +320,6 @@ class CoreExport DNS : public EventHandler int currid; /** - * We have to turn off a few checks on received packets - * when people are using 4in6 (e.g. ::ffff:xxxx). This is - * a temporary kludge, Please let me know if you know how - * to fix it. - */ - bool ip6munge; - - /** * Currently cached items */ dnscache* cache; @@ -344,20 +336,7 @@ class CoreExport DNS : public EventHandler public: - /** - * Server address being used currently - */ - int socketfamily; - - /** - * IPV6 server address - */ - in6_addr myserver6; - - /** - * IPV4 server address - */ - in_addr myserver4; + irc::sockets::sockaddrs myserver; /** * Currently active Resolver classes diff --git a/include/inspircd.h b/include/inspircd.h index f240c2ecb..b7827f315 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -421,10 +421,6 @@ class CoreExport InspIRCd : public classbase */ void BuildISupport(); - /** List of server names we've seen. - */ - servernamelist servernames; - /** Time this ircd was booted */ time_t startup_time; @@ -532,24 +528,6 @@ class CoreExport InspIRCd : public classbase */ bool BindSocket(int sockfd, int port, const char* addr, bool dolisten = true); - /** Adds a server name to the list of servers we've seen - * @param The servername to add - */ - void AddServerName(const std::string &servername); - - /** Finds a cached char* pointer of a server name, - * This is used to optimize User by storing only the pointer to the name - * @param The servername to find - * @return A pointer to this name, gauranteed to never become invalid - */ - const char* FindServerNamePtr(const std::string &servername); - - /** Returns true if we've seen the given server name before - * @param The servername to find - * @return True if we've seen this server name before - */ - bool FindServerName(const std::string &servername); - /** Gets the GECOS (description) field of the given server. * If the servername is not that of the local server, the name * is passed to handling modules which will attempt to determine diff --git a/include/socket.h b/include/socket.h index 6e4bf9dbd..2941606a3 100644 --- a/include/socket.h +++ b/include/socket.h @@ -96,7 +96,7 @@ namespace irc * or a negative value upon failure (negative values are invalid file * descriptors) */ - CoreExport int OpenTCPSocket(const char* addr, int socktype = SOCK_STREAM); + CoreExport int OpenTCPSocket(const std::string& addr, int socktype = SOCK_STREAM); /** Return the size of the structure for syscall passing */ CoreExport int sa_size(const irc::sockets::sockaddrs& sa); @@ -107,7 +107,7 @@ namespace irc * @param sa The structure to place the result in. Will be zeroed prior to conversion * @return true if the conversion was successful, false if not. */ - CoreExport bool aptosa(const char* addr, int port, irc::sockets::sockaddrs* sa); + CoreExport bool aptosa(const std::string& addr, int port, irc::sockets::sockaddrs* sa); /** Convert a binary sockaddr to an address-port pair * @param sa The structure to convert * @param addr the IP address diff --git a/include/typedefs.h b/include/typedefs.h index a40e6cfc2..fa4477f84 100644 --- a/include/typedefs.h +++ b/include/typedefs.h @@ -27,10 +27,6 @@ #endif #endif -/** Server name cache - */ -typedef std::vector<std::string*> servernamelist; - /** A cached text file stored line by line. */ typedef std::deque<std::string> file_cache; diff --git a/include/u_listmode.h b/include/u_listmode.h index cb211c9be..7c34605f4 100644 --- a/include/u_listmode.h +++ b/include/u_listmode.h @@ -180,7 +180,7 @@ class ListModeBase : public ModeHandler { for (modelist::reverse_iterator it = el->rbegin(); it != el->rend(); ++it) { - user->WriteNumeric(listnumeric, "%s %s %s %s %s", user->nick.c_str(), channel->name.c_str(), it->mask.c_str(), (it->nick.length() ? it->nick.c_str() : ServerInstance->Config->ServerName), it->time.c_str()); + user->WriteNumeric(listnumeric, "%s %s %s %s %s", user->nick.c_str(), channel->name.c_str(), it->mask.c_str(), (it->nick.length() ? it->nick.c_str() : ServerInstance->Config->ServerName.c_str()), it->time.c_str()); } } user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str()); diff --git a/src/channels.cpp b/src/channels.cpp index b250368b3..22ec6e4d9 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -158,7 +158,8 @@ const UserMembList* Channel::GetUsers() void Channel::SetDefaultModes() { - ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes); + ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", + ServerInstance->Config->DefaultModes.c_str()); irc::spacesepstream list(ServerInstance->Config->DefaultModes); std::string modeseq; std::string parameter; @@ -484,12 +485,13 @@ long Channel::PartUser(User *user, std::string &reason) return this->GetUserCounter(); } -long Channel::ServerKickUser(User* user, const char* reason, const char* servername) +long Channel::ServerKickUser(User* user, const char* reason, const std::string& servername) { - if (servername == NULL || *ServerInstance->Config->HideWhoisServer) - servername = ServerInstance->Config->ServerName; + if (servername.empty() || !ServerInstance->Config->HideWhoisServer.empty()) + ServerInstance->FakeClient->server = ServerInstance->Config->ServerName; + else + ServerInstance->FakeClient->server = servername; - ServerInstance->FakeClient->server = servername; return this->KickUser(ServerInstance->FakeClient, user, reason); } @@ -597,7 +599,7 @@ void Channel::WriteChannel(User* user, const std::string &text) } } -void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...) +void Channel::WriteChannelWithServ(const std::string& ServName, const char* text, ...) { char textbuffer[MAXBUF]; va_list argsPtr; @@ -612,11 +614,11 @@ void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...) this->WriteChannelWithServ(ServName, std::string(textbuffer)); } -void Channel::WriteChannelWithServ(const char* ServName, const std::string &text) +void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text) { char tb[MAXBUF]; - snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str()); + snprintf(tb,MAXBUF,":%s %s", ServName.empty() ? ServerInstance->Config->ServerName.c_str() : ServName.c_str(), text.c_str()); std::string out = tb; for (UserMembIter i = userlist.begin(); i != userlist.end(); i++) @@ -664,7 +666,7 @@ void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList { char tb[MAXBUF]; - snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName : user->GetFullHost().c_str(), text.c_str()); + snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str(), text.c_str()); std::string out = tb; this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb)); diff --git a/src/commands/cmd_admin.cpp b/src/commands/cmd_admin.cpp index 1f2641e67..01017f69c 100644 --- a/src/commands/cmd_admin.cpp +++ b/src/commands/cmd_admin.cpp @@ -47,11 +47,11 @@ class CommandAdmin : public Command */ CmdResult CommandAdmin::Handle (const std::vector<std::string>& parameters, User *user) { - user->WriteNumeric(RPL_ADMINME, "%s :Administrative info for %s",user->nick.c_str(),ServerInstance->Config->ServerName); - if (*ServerInstance->Config->AdminName) - user->WriteNumeric(RPL_ADMINLOC1, "%s :Name - %s",user->nick.c_str(),ServerInstance->Config->AdminName); - user->WriteNumeric(RPL_ADMINLOC2, "%s :Nickname - %s",user->nick.c_str(),ServerInstance->Config->AdminNick); - user->WriteNumeric(RPL_ADMINEMAIL, "%s :E-Mail - %s",user->nick.c_str(),ServerInstance->Config->AdminEmail); + user->WriteNumeric(RPL_ADMINME, "%s :Administrative info for %s",user->nick.c_str(),ServerInstance->Config->ServerName.c_str()); + if (!ServerInstance->Config->AdminName.empty()) + user->WriteNumeric(RPL_ADMINLOC1, "%s :Name - %s",user->nick.c_str(),ServerInstance->Config->AdminName.c_str()); + user->WriteNumeric(RPL_ADMINLOC2, "%s :Nickname - %s",user->nick.c_str(),ServerInstance->Config->AdminNick.c_str()); + user->WriteNumeric(RPL_ADMINEMAIL, "%s :E-Mail - %s",user->nick.c_str(),ServerInstance->Config->AdminEmail.c_str()); return CMD_SUCCESS; } diff --git a/src/commands/cmd_kill.cpp b/src/commands/cmd_kill.cpp index 88db2764d..8bbc7ad0b 100644 --- a/src/commands/cmd_kill.cpp +++ b/src/commands/cmd_kill.cpp @@ -65,10 +65,10 @@ CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User if (MOD_RESULT == MOD_RES_DENY) return CMD_FAILURE; - if (*ServerInstance->Config->HideKillsServer) + if (!ServerInstance->Config->HideKillsServer.empty()) { // hidekills is on, use it - snprintf(killreason, ServerInstance->Config->Limits.MaxQuit, "Killed (%s (%s))", ServerInstance->Config->HideKillsServer, parameters[1].c_str()); + snprintf(killreason, ServerInstance->Config->Limits.MaxQuit, "Killed (%s (%s))", ServerInstance->Config->HideKillsServer.c_str(), parameters[1].c_str()); } else { @@ -100,17 +100,17 @@ CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User * snotices, C will get a local kill snotice. this isn't accurate, and needs fixing at some stage. -- w00t */ ServerInstance->SNO->WriteToSnoMask('k',"Local Kill by %s: %s!%s@%s (%s)", user->nick.c_str(), u->nick.c_str(), u->ident.c_str(), u->host.c_str(), parameters[1].c_str()); - ServerInstance->Logs->Log("KILL",DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick.c_str(), ServerInstance->Config->ServerName, user->dhost.c_str(), user->nick.c_str(), parameters[1].c_str()); + ServerInstance->Logs->Log("KILL",DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick.c_str(), ServerInstance->Config->ServerName.c_str(), user->dhost.c_str(), user->nick.c_str(), parameters[1].c_str()); /* Bug #419, make sure this message can only occur once even in the case of multiple KILL messages crossing the network, and change to show * hidekillsserver as source if possible */ if (!u->quitting) { - u->Write(":%s KILL %s :%s!%s!%s (%s)", *ServerInstance->Config->HideKillsServer ? ServerInstance->Config->HideKillsServer : user->GetFullHost().c_str(), + u->Write(":%s KILL %s :%s!%s!%s (%s)", ServerInstance->Config->HideKillsServer.empty() ? user->GetFullHost().c_str() : ServerInstance->Config->HideKillsServer.c_str(), u->nick.c_str(), - ServerInstance->Config->ServerName, + ServerInstance->Config->ServerName.c_str(), user->dhost.c_str(), - *ServerInstance->Config->HideKillsServer ? ServerInstance->Config->HideKillsServer : user->nick.c_str(), + ServerInstance->Config->HideKillsServer.empty() ? user->nick.c_str() : ServerInstance->Config->HideKillsServer.c_str(), parameters[1].c_str()); } } diff --git a/src/commands/cmd_links.cpp b/src/commands/cmd_links.cpp index d722fa65d..3fcaf1e4d 100644 --- a/src/commands/cmd_links.cpp +++ b/src/commands/cmd_links.cpp @@ -48,7 +48,7 @@ class CommandLinks : public Command */ CmdResult CommandLinks::Handle (const std::vector<std::string>&, User *user) { - user->WriteNumeric(364, "%s %s %s :0 %s",user->nick.c_str(),ServerInstance->Config->ServerName,ServerInstance->Config->ServerName,ServerInstance->Config->ServerDesc); + user->WriteNumeric(364, "%s %s %s :0 %s",user->nick.c_str(),ServerInstance->Config->ServerName.c_str(),ServerInstance->Config->ServerName.c_str(),ServerInstance->Config->ServerDesc.c_str()); user->WriteNumeric(365, "%s * :End of /LINKS list.",user->nick.c_str()); return CMD_SUCCESS; } diff --git a/src/commands/cmd_map.cpp b/src/commands/cmd_map.cpp index b6846954a..074ca9248 100644 --- a/src/commands/cmd_map.cpp +++ b/src/commands/cmd_map.cpp @@ -38,11 +38,11 @@ CmdResult CommandMap::Handle (const std::vector<std::string>&, User *user) if (IS_OPER(user)) { - user->WriteNumeric(006, "%s :%s [%s]", user->nick.c_str(), ServerInstance->Config->ServerName, ServerInstance->Config->GetSID().c_str()); + user->WriteNumeric(006, "%s :%s [%s]", user->nick.c_str(), ServerInstance->Config->ServerName.c_str(), ServerInstance->Config->GetSID().c_str()); user->WriteNumeric(007, "%s :End of /MAP", user->nick.c_str()); return CMD_SUCCESS; } - user->WriteNumeric(006, "%s :%s",user->nick.c_str(),ServerInstance->Config->ServerName); + user->WriteNumeric(006, "%s :%s",user->nick.c_str(),ServerInstance->Config->ServerName.c_str()); user->WriteNumeric(007, "%s :End of /MAP",user->nick.c_str()); return CMD_SUCCESS; diff --git a/src/commands/cmd_modules.cpp b/src/commands/cmd_modules.cpp index 76cc29ac6..1b0f1da13 100644 --- a/src/commands/cmd_modules.cpp +++ b/src/commands/cmd_modules.cpp @@ -58,16 +58,16 @@ CmdResult CommandModules::Handle (const std::vector<std::string>&, User *user) if (!(V.Flags & mult)) flags[pos] = '-'; - ServerInstance->DumpText(user, ":%s 702 %s :%p %s %s :%s - %s", ServerInstance->Config->ServerName, + ServerInstance->DumpText(user, ":%s 702 %s :%p %s %s :%s - %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), (void*)m, module_names[i].c_str(), flags.c_str(), V.description.c_str(), V.version.c_str()); } else { - ServerInstance->DumpText(user, ":%s 702 %s :%s %s", ServerInstance->Config->ServerName, + ServerInstance->DumpText(user, ":%s 702 %s :%s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), module_names[i].c_str(), V.description.c_str()); } } - ServerInstance->DumpText(user, ":%s 703 %s :End of MODULES list", ServerInstance->Config->ServerName, user->nick.c_str()); + ServerInstance->DumpText(user, ":%s 703 %s :End of MODULES list", ServerInstance->Config->ServerName.c_str(), user->nick.c_str()); return CMD_SUCCESS; } diff --git a/src/commands/cmd_part.cpp b/src/commands/cmd_part.cpp index e2e4e59a0..a7a407ac8 100644 --- a/src/commands/cmd_part.cpp +++ b/src/commands/cmd_part.cpp @@ -39,12 +39,12 @@ CmdResult CommandPart::Handle (const std::vector<std::string>& parameters, User if (IS_LOCAL(user)) { - if (*ServerInstance->Config->FixedPart) + if (!ServerInstance->Config->FixedPart.empty()) reason = ServerInstance->Config->FixedPart; else { if (parameters.size() > 1) - reason = ServerInstance->Config->PrefixPart + std::string(parameters[1]) + ServerInstance->Config->SuffixPart; + reason = ServerInstance->Config->PrefixPart + parameters[1] + ServerInstance->Config->SuffixPart; else reason = ""; } diff --git a/src/commands/cmd_ping.cpp b/src/commands/cmd_ping.cpp index e7898921a..b009bda84 100644 --- a/src/commands/cmd_ping.cpp +++ b/src/commands/cmd_ping.cpp @@ -35,7 +35,7 @@ class CommandPing : public Command CmdResult CommandPing::Handle (const std::vector<std::string>& parameters, User *user) { - user->WriteServ("PONG %s :%s", ServerInstance->Config->ServerName, parameters[0].c_str()); + user->WriteServ("PONG %s :%s", ServerInstance->Config->ServerName.c_str(), parameters[0].c_str()); return CMD_SUCCESS; } diff --git a/src/commands/cmd_quit.cpp b/src/commands/cmd_quit.cpp index d041fc031..5db7ada40 100644 --- a/src/commands/cmd_quit.cpp +++ b/src/commands/cmd_quit.cpp @@ -41,7 +41,7 @@ CmdResult CommandQuit::Handle (const std::vector<std::string>& parameters, User if (IS_LOCAL(user)) { - if (*ServerInstance->Config->FixedQuit) + if (!ServerInstance->Config->FixedQuit.empty()) quitmsg = ServerInstance->Config->FixedQuit; else quitmsg = parameters.size() ? diff --git a/src/commands/cmd_time.cpp b/src/commands/cmd_time.cpp index 8ff588c2d..16cb76c7d 100644 --- a/src/commands/cmd_time.cpp +++ b/src/commands/cmd_time.cpp @@ -57,7 +57,7 @@ CmdResult CommandTime::Handle (const std::vector<std::string>&, User *user) snprintf(tms,26,"%s",asctime(timeinfo)); tms[24] = 0; - user->WriteNumeric(RPL_TIME, "%s %s :%s",user->nick.c_str(),ServerInstance->Config->ServerName,tms); + user->WriteNumeric(RPL_TIME, "%s %s :%s",user->nick.c_str(),ServerInstance->Config->ServerName.c_str(),tms); return CMD_SUCCESS; } diff --git a/src/commands/cmd_who.cpp b/src/commands/cmd_who.cpp index 89ca60d02..49fb26a2f 100644 --- a/src/commands/cmd_who.cpp +++ b/src/commands/cmd_who.cpp @@ -148,7 +148,7 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext) match = InspIRCd::Match(user->nick, matchtext); /* Don't allow server name matches if HideWhoisServer is enabled, unless the command user has the priv */ - if (!match && (!*ServerInstance->Config->HideWhoisServer || cuser->HasPrivPermission("users/auspex"))) + if (!match && (ServerInstance->Config->HideWhoisServer.empty() || cuser->HasPrivPermission("users/auspex"))) match = InspIRCd::Match(user->server, matchtext); return match; @@ -183,7 +183,7 @@ void CommandWho::SendWhoLine(User* user, const std::string &initial, Channel* ch Channel* chlast = ServerInstance->FindChan(lcn); std::string wholine = initial + (ch ? ch->name : lcn) + " " + u->ident + " " + (opt_showrealhost ? u->host : u->dhost) + " " + - ((*ServerInstance->Config->HideWhoisServer && !user->HasPrivPermission("servers/auspex")) ? ServerInstance->Config->HideWhoisServer : u->server) + + ((!ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex")) ? ServerInstance->Config->HideWhoisServer : u->server) + " " + u->nick + " "; /* away? */ @@ -255,9 +255,6 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User * } } - if (ServerInstance->FindServerName(matchtext)) - usingwildcards = true; - if (parameters.size() > 1) { /* Fix for bug #444, WHO flags count as a wildcard */ @@ -300,11 +297,11 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User * opt_away = true; break; case 'l': - if (user->HasPrivPermission("users/auspex") || !*ServerInstance->Config->HideWhoisServer) + if (user->HasPrivPermission("users/auspex") || ServerInstance->Config->HideWhoisServer.empty()) opt_local = true; break; case 'f': - if (user->HasPrivPermission("users/auspex") || !*ServerInstance->Config->HideWhoisServer) + if (user->HasPrivPermission("users/auspex") || ServerInstance->Config->HideWhoisServer.empty()) opt_far = true; break; case 't': diff --git a/src/commands/cmd_whois.cpp b/src/commands/cmd_whois.cpp index 972b0439e..37806df07 100644 --- a/src/commands/cmd_whois.cpp +++ b/src/commands/cmd_whois.cpp @@ -66,7 +66,7 @@ CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User * For remote users (/w remoteuser remoteuser), spanningtree will handle calling do_whois, so we can ignore this case. * Thanks to djGrrr for not being impatient while I have a crap day coding. :p -- w00t */ - if (IS_LOCAL(dest) && (!*ServerInstance->Config->HideWhoisServer || parameters.size() > 1)) + if (IS_LOCAL(dest) && (ServerInstance->Config->HideWhoisServer.empty() || parameters.size() > 1)) { idle = abs((long)((dest->idle_lastmsg)-ServerInstance->Time())); signon = dest->signon; diff --git a/src/commands/cmd_whowas.cpp b/src/commands/cmd_whowas.cpp index 6cd50f8b8..837e5d016 100644 --- a/src/commands/cmd_whowas.cpp +++ b/src/commands/cmd_whowas.cpp @@ -65,8 +65,8 @@ CmdResult CommandWhowas::Handle (const std::vector<std::string>& parameters, Use user->WriteNumeric(379, "%s %s :was connecting from *@%s", user->nick.c_str(), parameters[0].c_str(), u->host.c_str()); - if (*ServerInstance->Config->HideWhoisServer && !user->HasPrivPermission("servers/auspex")) - user->WriteNumeric(312, "%s %s %s :%s",user->nick.c_str(),parameters[0].c_str(), ServerInstance->Config->HideWhoisServer, b); + if (!ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex")) + user->WriteNumeric(312, "%s %s %s :%s",user->nick.c_str(),parameters[0].c_str(), ServerInstance->Config->HideWhoisServer.c_str(), b); else user->WriteNumeric(312, "%s %s %s :%s",user->nick.c_str(),parameters[0].c_str(), u->server.c_str(), b); } diff --git a/src/configreader.cpp b/src/configreader.cpp index 86d0b3c5e..21e4c2321 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -34,10 +34,6 @@ ServerConfig::ServerConfig() { - *sid = *ServerName = *Network = *ServerDesc = *AdminName = '\0'; - *HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = *FixedQuit = *HideKillsServer = '\0'; - *DefaultModes = *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0'; - *UserStats = *DisabledCommands = *SuffixQuit = '\0'; WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0; log_file = NULL; NoUserDns = forcedebug = OperSpyWhois = nofork = HideBans = HideSplits = UndernetMsgPrefix = false; @@ -222,7 +218,7 @@ static bool ValidateMaxConn(ServerConfig* conf, const char*, const char*, ValueI return true; } -bool ServerConfig::ApplyDisabledCommands(const char* data) +bool ServerConfig::ApplyDisabledCommands(const std::string& data) { std::stringstream dcmds(data); std::string thiscmd; @@ -421,7 +417,7 @@ static bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem 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."); } - strlcpy(conf->sid, sid, 5); + conf->sid = sid; return true; } @@ -756,45 +752,45 @@ static const Deprecated ChangedConfig[] = { static const InitialConfig Values[] = { {"performance", "softlimit", "0", new ValueContainerUInt (&ServerConfig::SoftLimit), DT_INTEGER, ValidateSoftLimit}, {"performance", "somaxconn", SOMAXCONN_S, new ValueContainerInt (&ServerConfig::MaxConn), DT_INTEGER, ValidateMaxConn}, - {"options", "moronbanner", "You're banned!", new ValueContainerChar (&ServerConfig::MoronBanner), DT_CHARPTR, NULL}, - {"server", "name", "", new ValueContainerChar (&ServerConfig::ServerName), DT_HOSTNAME, ValidateServerName}, - {"server", "description", "Configure Me", new ValueContainerChar (&ServerConfig::ServerDesc), DT_CHARPTR, NULL}, - {"server", "network", "Network", new ValueContainerChar (&ServerConfig::Network), DT_NOSPACES, NULL}, - {"server", "id", "", new ValueContainerChar (&ServerConfig::sid), DT_CHARPTR, ValidateSID}, - {"admin", "name", "", new ValueContainerChar (&ServerConfig::AdminName), DT_CHARPTR, NULL}, - {"admin", "email", "Mis@configu.red", new ValueContainerChar (&ServerConfig::AdminEmail), DT_CHARPTR, NULL}, - {"admin", "nick", "Misconfigured", new ValueContainerChar (&ServerConfig::AdminNick), DT_CHARPTR, NULL}, - {"files", "motd", "", new ValueContainerChar (&ServerConfig::motd), DT_CHARPTR, ValidateMotd}, - {"files", "rules", "", new ValueContainerChar (&ServerConfig::rules), DT_CHARPTR, ValidateRules}, - {"power", "diepass", "", new ValueContainerChar (&ServerConfig::diepass), DT_CHARPTR, ValidateNotEmpty}, + {"options", "moronbanner", "You're banned!", new ValueContainerString (&ServerConfig::MoronBanner), DT_CHARPTR, NULL}, + {"server", "name", "", new ValueContainerString (&ServerConfig::ServerName), DT_HOSTNAME, ValidateServerName}, + {"server", "description", "Configure Me", new ValueContainerString (&ServerConfig::ServerDesc), DT_CHARPTR, NULL}, + {"server", "network", "Network", new ValueContainerString (&ServerConfig::Network), DT_NOSPACES, NULL}, + {"server", "id", "", new ValueContainerString (&ServerConfig::sid), DT_CHARPTR, ValidateSID}, + {"admin", "name", "", new ValueContainerString (&ServerConfig::AdminName), DT_CHARPTR, NULL}, + {"admin", "email", "Mis@configu.red", new ValueContainerString (&ServerConfig::AdminEmail), DT_CHARPTR, NULL}, + {"admin", "nick", "Misconfigured", new ValueContainerString (&ServerConfig::AdminNick), DT_CHARPTR, NULL}, + {"files", "motd", "", new ValueContainerString (&ServerConfig::motd), DT_CHARPTR, ValidateMotd}, + {"files", "rules", "", new ValueContainerString (&ServerConfig::rules), DT_CHARPTR, ValidateRules}, + {"power", "diepass", "", new ValueContainerString (&ServerConfig::diepass), DT_CHARPTR, ValidateNotEmpty}, {"power", "pause", "", new ValueContainerInt (&ServerConfig::DieDelay), DT_INTEGER, NULL}, - {"power", "hash", "", new ValueContainerChar (&ServerConfig::powerhash), DT_CHARPTR, NULL}, - {"power", "restartpass", "", new ValueContainerChar (&ServerConfig::restartpass), DT_CHARPTR, ValidateNotEmpty}, - {"options", "prefixquit", "", new ValueContainerChar (&ServerConfig::PrefixQuit), DT_CHARPTR, NULL}, - {"options", "suffixquit", "", new ValueContainerChar (&ServerConfig::SuffixQuit), DT_CHARPTR, NULL}, - {"options", "fixedquit", "", new ValueContainerChar (&ServerConfig::FixedQuit), DT_CHARPTR, NULL}, - {"options", "prefixpart", "", new ValueContainerChar (&ServerConfig::PrefixPart), DT_CHARPTR, NULL}, - {"options", "suffixpart", "", new ValueContainerChar (&ServerConfig::SuffixPart), DT_CHARPTR, NULL}, - {"options", "fixedpart", "", new ValueContainerChar (&ServerConfig::FixedPart), DT_CHARPTR, NULL}, + {"power", "hash", "", new ValueContainerString (&ServerConfig::powerhash), DT_CHARPTR, NULL}, + {"power", "restartpass", "", new ValueContainerString (&ServerConfig::restartpass), DT_CHARPTR, ValidateNotEmpty}, + {"options", "prefixquit", "", new ValueContainerString (&ServerConfig::PrefixQuit), DT_CHARPTR, NULL}, + {"options", "suffixquit", "", new ValueContainerString (&ServerConfig::SuffixQuit), DT_CHARPTR, NULL}, + {"options", "fixedquit", "", new ValueContainerString (&ServerConfig::FixedQuit), DT_CHARPTR, NULL}, + {"options", "prefixpart", "", new ValueContainerString (&ServerConfig::PrefixPart), DT_CHARPTR, NULL}, + {"options", "suffixpart", "", new ValueContainerString (&ServerConfig::SuffixPart), DT_CHARPTR, NULL}, + {"options", "fixedpart", "", new ValueContainerString (&ServerConfig::FixedPart), DT_CHARPTR, NULL}, {"performance", "netbuffersize","10240", new ValueContainerInt (&ServerConfig::NetBufferSize), DT_INTEGER, ValidateNetBufferSize}, {"performance", "maxwho", "1024", new ValueContainerInt (&ServerConfig::MaxWhoResults), DT_INTEGER, ValidateMaxWho}, {"options", "allowhalfop", "0", new ValueContainerBool (&ServerConfig::AllowHalfop), DT_BOOLEAN, ValidateHalfOp}, - {"dns", "server", "", new ValueContainerChar (&ServerConfig::DNSServer), DT_IPADDRESS,ValidateDnsServer}, + {"dns", "server", "", new ValueContainerString (&ServerConfig::DNSServer), DT_IPADDRESS,ValidateDnsServer}, {"dns", "timeout", "5", new ValueContainerInt (&ServerConfig::dns_timeout), DT_INTEGER, NULL}, {"options", "moduledir", MOD_PATH, new ValueContainerString (&ServerConfig::ModPath), DT_CHARPTR, NULL}, - {"disabled", "commands", "", new ValueContainerChar (&ServerConfig::DisabledCommands), DT_CHARPTR, NULL}, + {"disabled", "commands", "", new ValueContainerString (&ServerConfig::DisabledCommands), DT_CHARPTR, NULL}, {"disabled", "usermodes", "", NULL, DT_NOTHING, ValidateDisabledUModes}, {"disabled", "chanmodes", "", NULL, DT_NOTHING, ValidateDisabledCModes}, {"disabled", "fakenonexistant", "0", new ValueContainerBool (&ServerConfig::DisabledDontExist), DT_BOOLEAN, NULL}, - {"security", "runasuser", "", new ValueContainerChar(&ServerConfig::SetUser), DT_CHARPTR, NULL}, - {"security", "runasgroup", "", new ValueContainerChar(&ServerConfig::SetGroup), DT_CHARPTR, NULL}, - {"security", "userstats", "", new ValueContainerChar (&ServerConfig::UserStats), DT_CHARPTR, NULL}, - {"security", "customversion","", new ValueContainerChar (&ServerConfig::CustomVersion), DT_CHARPTR, NULL}, + {"security", "runasuser", "", new ValueContainerString(&ServerConfig::SetUser), DT_CHARPTR, NULL}, + {"security", "runasgroup", "", new ValueContainerString(&ServerConfig::SetGroup), DT_CHARPTR, NULL}, + {"security", "userstats", "", new ValueContainerString (&ServerConfig::UserStats), DT_CHARPTR, NULL}, + {"security", "customversion","", new ValueContainerString (&ServerConfig::CustomVersion), DT_CHARPTR, NULL}, {"security", "hidesplits", "0", new ValueContainerBool (&ServerConfig::HideSplits), DT_BOOLEAN, NULL}, {"security", "hidebans", "0", new ValueContainerBool (&ServerConfig::HideBans), DT_BOOLEAN, NULL}, - {"security", "hidewhois", "", new ValueContainerChar (&ServerConfig::HideWhoisServer), DT_NOSPACES, NULL}, - {"security", "hidekills", "", new ValueContainerChar (&ServerConfig::HideKillsServer), DT_NOSPACES, NULL}, + {"security", "hidewhois", "", new ValueContainerString (&ServerConfig::HideWhoisServer), DT_NOSPACES, NULL}, + {"security", "hidekills", "", new ValueContainerString (&ServerConfig::HideKillsServer), DT_NOSPACES, NULL}, {"security", "operspywhois", "0", new ValueContainerBool (&ServerConfig::OperSpyWhois), DT_BOOLEAN, NULL}, {"security", "restrictbannedusers", "1", new ValueContainerBool (&ServerConfig::RestrictBannedUsers), DT_BOOLEAN, NULL}, {"security", "genericoper", "0", new ValueContainerBool (&ServerConfig::GenericOper), DT_BOOLEAN, NULL}, @@ -807,12 +803,12 @@ static const InitialConfig Values[] = { {"security", "hidemodes", "", NULL, DT_NOTHING, ValidateModeLists}, {"options", "exemptchanops","", NULL, DT_NOTHING, ValidateExemptChanOps}, {"security", "maxtargets", "20", new ValueContainerUInt (&ServerConfig::MaxTargets), DT_INTEGER, ValidateMaxTargets}, - {"options", "defaultmodes", "nt", new ValueContainerChar (&ServerConfig::DefaultModes), DT_CHARPTR, NULL}, + {"options", "defaultmodes", "nt", new ValueContainerString (&ServerConfig::DefaultModes), DT_CHARPTR, NULL}, {"pid", "file", "", new ValueContainerString (&ServerConfig::PID), DT_CHARPTR, NULL}, {"whowas", "groupsize", "10", new ValueContainerInt (&ServerConfig::WhoWasGroupSize), DT_INTEGER, NULL}, {"whowas", "maxgroups", "10240", new ValueContainerInt (&ServerConfig::WhoWasMaxGroups), DT_INTEGER, NULL}, {"whowas", "maxkeep", "3600", NULL, DT_NOTHING, ValidateWhoWas}, - {"die", "value", "", new ValueContainerChar (&ServerConfig::DieValue), DT_CHARPTR, NULL}, + {"die", "value", "", new ValueContainerString (&ServerConfig::DieValue), DT_CHARPTR, NULL}, {"channels", "users", "20", new ValueContainerUInt (&ServerConfig::MaxChans), DT_INTEGER, NULL}, {"channels", "opers", "60", new ValueContainerUInt (&ServerConfig::OperMaxChans), DT_INTEGER, NULL}, {"cidr", "ipv4clone", "32", new ValueContainerInt (&ServerConfig::c_ipv4_range), DT_INTEGER, NULL}, @@ -964,40 +960,37 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) { case DT_NOSPACES: { - ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val; + ValueContainerString* vcc = (ValueContainerString*)Values[Index].val; ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value); - vcc->Set(this, vi); + vcc->Set(this, vi.GetValue()); } break; case DT_HOSTNAME: { - ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val; + ValueContainerString* vcc = (ValueContainerString*)Values[Index].val; ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value); - vcc->Set(this, vi); + vcc->Set(this, vi.GetValue()); } break; case DT_IPADDRESS: { - ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val; + ValueContainerString* vcc = (ValueContainerString*)Values[Index].val; ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild); - vcc->Set(this, vi); + vcc->Set(this, vi.GetValue()); } break; case DT_CHANNEL: { - ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val; + ValueContainerString* vcc = (ValueContainerString*)Values[Index].val; if (*(vi.GetString()) && !ServerInstance->IsChannel(vi.GetString(), MAXBUF)) { throw CoreException("The value of <"+std::string(Values[Index].tag)+":"+Values[Index].value+"> is not a valid channel name"); } - vcc->Set(this, vi); + vcc->Set(this, vi.GetValue()); } break; case DT_CHARPTR: { - ValueContainerChar* vcc = dynamic_cast<ValueContainerChar*>(Values[Index].val); - if (vcc) - vcc->Set(this, vi); ValueContainerString* vcs = dynamic_cast<ValueContainerString*>(Values[Index].val); if (vcs) vcs->Set(this, vi.GetValue()); @@ -1143,8 +1136,8 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) */ if (old) { - memcpy(this->ServerName, old->ServerName, sizeof(this->ServerName)); - memcpy(this->sid, old->sid, sizeof(this->sid)); + this->ServerName = old->ServerName; + this->sid = old->sid; this->argv = old->argv; this->argc = old->argc; diff --git a/src/dns.cpp b/src/dns.cpp index 718a1698f..2e016f58e 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -216,26 +216,16 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp DNS::EmptyHeader(payload,header,length); - if (this->dnsobj->socketfamily == AF_INET6) + if (this->dnsobj->myserver.sa.sa_family == AF_INET6) { - sockaddr_in6 addr; - memset(&addr,0,sizeof(addr)); - memcpy(&addr.sin6_addr,&dnsobj->myserver6,sizeof(addr.sin6_addr)); - addr.sin6_family = AF_INET6; - addr.sin6_port = htons(DNS::QUERY_PORT); - if (ServerInstance->SE->SendTo(dnsobj, payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) != length+12) - return -1; + dnsobj->myserver.in6.sin6_port = htons(DNS::QUERY_PORT); } else { - sockaddr_in addr; - memset(&addr,0,sizeof(addr)); - memcpy(&addr.sin_addr.s_addr,&dnsobj->myserver4,sizeof(addr.sin_addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(DNS::QUERY_PORT); - if (ServerInstance->SE->SendTo(dnsobj, (const char*)payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) != length+12) - return -1; + dnsobj->myserver.in4.sin_port = htons(DNS::QUERY_PORT); } + if (ServerInstance->SE->SendTo(dnsobj, payload, length + 12, 0, &(dnsobj->myserver.sa), sa_size(dnsobj->myserver)) != length+12) + return -1; ServerInstance->Logs->Log("RESOLVER",DEBUG,"Sent OK"); return 0; @@ -302,7 +292,6 @@ int DNS::PruneCache() void DNS::Rehash() { - ip6munge = false; int portpass = 0; if (this->GetFd() > -1) @@ -322,25 +311,7 @@ void DNS::Rehash() this->cache = new dnscache(); } - if ((strstr(ServerInstance->Config->DNSServer,"::ffff:") == (char*)&ServerInstance->Config->DNSServer) || (strstr(ServerInstance->Config->DNSServer,"::FFFF:") == (char*)&ServerInstance->Config->DNSServer)) - { - ServerInstance->Logs->Log("RESOLVER",DEFAULT,"WARNING: Using IPv4 addresses over IPv6 forces some DNS checks to be disabled."); - ServerInstance->Logs->Log("RESOLVER",DEFAULT," This should not cause a problem, however it is recommended you migrate"); - ServerInstance->Logs->Log("RESOLVER",DEFAULT," to a true IPv6 environment."); - this->ip6munge = true; - } - - this->socketfamily = AF_INET; - if (strchr(ServerInstance->Config->DNSServer,':')) - { - this->socketfamily = AF_INET6; - inet_pton(AF_INET6, ServerInstance->Config->DNSServer, &this->myserver6); - } - else - { - inet_aton(ServerInstance->Config->DNSServer, &this->myserver4); - portpass = -1; - } + irc::sockets::aptosa(ServerInstance->Config->DNSServer, 0, &myserver); /* Initialize mastersocket */ int s = irc::sockets::OpenTCPSocket(ServerInstance->Config->DNSServer, SOCK_DGRAM); @@ -573,9 +544,8 @@ DNSResult DNS::GetResult() DNSRequest *req; unsigned char buffer[sizeof(DNSHeader)]; irc::sockets::sockaddrs from; - socklen_t x = this->socketfamily == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6); - const char* ipaddr_from; - unsigned short int port_from = 0; + memset(&from, 0, sizeof(from)); + socklen_t x = sizeof(from); int length = ServerInstance->SE->RecvFrom(this, (char*)buffer, sizeof(DNSHeader), 0, &from.sa, &x); @@ -591,31 +561,16 @@ DNSResult DNS::GetResult() * is not 53. * A user could in theory still spoof dns packets anyway * but this is less trivial than just sending garbage - * to the client, which is possible without this check. + * to the server, which is possible without this check. * * -- Thanks jilles for pointing this one out. */ - char nbuf[MAXBUF]; - if (this->socketfamily == AF_INET6) - { - ipaddr_from = inet_ntop(AF_INET6, &from.in6.sin6_addr, nbuf, sizeof(nbuf)); - port_from = ntohs(from.in6.sin6_port); - } - else - { - ipaddr_from = inet_ntoa(from.in4.sin_addr); - port_from = ntohs(from.in4.sin_port); - } + irc::sockets::sockaddrs expect_src; + irc::sockets::aptosa(ServerInstance->Config->DNSServer, DNS::QUERY_PORT, &expect_src); - /* We cant perform this security check if you're using 4in6. - * Tough luck to you, choose one or't other! - */ - if (!ip6munge) + if (memcmp(&from, &expect_src, sizeof(irc::sockets::sockaddrs))) { - if ((port_from != DNS::QUERY_PORT) || (strcasecmp(ipaddr_from, ServerInstance->Config->DNSServer))) - { - return DNSResult(-1,"",0,""); - } + return DNSResult(-1,"",0,""); } /* Put the read header info into a header class */ diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 2a9f506bc..2a6bc4e0a 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -111,10 +111,6 @@ void InspIRCd::Cleanup() Users->QuitUser(u, "Server shutdown"); } - /* Cleanup Server Names */ - for(servernamelist::iterator itr = servernames.begin(); itr != servernames.end(); ++itr) - delete (*itr); - /* We do this more than once, so that any service providers get a * chance to be unhooked by the modules using them, but then get * a chance to be removed themsleves. @@ -563,28 +559,23 @@ InspIRCd::InspIRCd(int argc, char** argv) : this->Res = new DNS; - this->AddServerName(Config->ServerName); - /* * Initialise SID/UID. * For an explanation as to exactly how this works, and why it works this way, see GetUID(). * -- w00t */ - if (!*Config->sid) + if (Config->sid.empty()) { // Generate one size_t sid = 0; - for (const char* x = Config->ServerName; *x; ++x) + for (const char* x = Config->ServerName.c_str(); *x; ++x) sid = 5 * sid + *x; - for (const char* y = Config->ServerDesc; *y; ++y) + for (const char* y = Config->ServerDesc.c_str(); *y; ++y) sid = 5 * sid + *y; sid = sid % 999; - Config->sid[0] = (char)(sid / 100 + 48); - Config->sid[1] = (char)(((sid / 10) % 10) + 48); - Config->sid[2] = (char)(sid % 10 + 48); - Config->sid[3] = '\0'; + Config->sid = ConvToStr(sid); } /* set up fake client again this time with the correct uid */ @@ -618,7 +609,8 @@ InspIRCd::InspIRCd(int argc, char** argv) : } } - printf("\nInspIRCd is now running as '%s'[%s] with %d max open sockets\n", Config->ServerName,Config->GetSID().c_str(), SE->GetMaxFds()); + printf("\nInspIRCd is now running as '%s'[%s] with %d max open sockets\n", + Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds()); #ifndef WINDOWS if (!Config->nofork) @@ -658,10 +650,10 @@ InspIRCd::InspIRCd(int argc, char** argv) : SetServiceRunning(); #endif - Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName,Config->GetSID().c_str(), SE->GetMaxFds()); + Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds()); #ifndef WIN32 - if (*(this->Config->SetGroup)) + if (!Config->SetGroup.empty()) { int ret; @@ -678,7 +670,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : struct group *g; errno = 0; - g = getgrnam(this->Config->SetGroup); + g = getgrnam(this->Config->SetGroup.c_str()); if (!g) { @@ -695,13 +687,13 @@ InspIRCd::InspIRCd(int argc, char** argv) : } } - if (*(this->Config->SetUser)) + if (!Config->SetUser.empty()) { // setuid struct passwd *u; errno = 0; - u = getpwnam(this->Config->SetUser); + u = getpwnam(this->Config->SetUser.c_str()); if (!u) { diff --git a/src/modules/m_alltime.cpp b/src/modules/m_alltime.cpp index 37f6a5fd2..63e8067e3 100644 --- a/src/modules/m_alltime.cpp +++ b/src/modules/m_alltime.cpp @@ -30,7 +30,7 @@ class CommandAlltime : public Command time_t now = ServerInstance->Time(); strftime(fmtdate, sizeof(fmtdate), "%Y-%m-%d %H:%M:%S", gmtime(&now)); - std::string msg = ":" + std::string(ServerInstance->Config->ServerName) + " NOTICE " + user->nick + " :System time is " + fmtdate + "(" + ConvToStr(ServerInstance->Time()) + ") on " + ServerInstance->Config->ServerName; + std::string msg = ":" + std::string(ServerInstance->Config->ServerName.c_str()) + " NOTICE " + user->nick + " :System time is " + fmtdate + "(" + ConvToStr(ServerInstance->Time()) + ") on " + ServerInstance->Config->ServerName; ServerInstance->DumpText(user, msg); diff --git a/src/modules/m_antibear.cpp b/src/modules/m_antibear.cpp index a89e9dd4d..5f53b5fbb 100644 --- a/src/modules/m_antibear.cpp +++ b/src/modules/m_antibear.cpp @@ -42,7 +42,7 @@ class ModuleAntiBear : public Module { if (!strncmp(parameters[1].c_str(), "\1TIME Mon May 01 18:54:20 2006", 30)) { - ZLine* zl = new ZLine(ServerInstance->Time(), 86400, ServerInstance->Config->ServerName, + ZLine* zl = new ZLine(ServerInstance->Time(), 86400, ServerInstance->Config->ServerName.c_str(), "Unless you're stuck in a time warp, you appear to be a bear bot!", user->GetIPString()); if (ServerInstance->XLines->AddLine(zl,NULL)) { diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 45d3f0e5c..b0d8f54b7 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -391,7 +391,7 @@ public: { user->WriteNumeric(717, "%s %s :has been informed that you messaged them.", user->nick.c_str(), dest->nick.c_str()); ServerInstance->DumpText(dest, ":%s 718 %s %s %s@%s :is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.", - ServerInstance->Config->ServerName, dest->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), user->nick.c_str()); + ServerInstance->Config->ServerName.c_str(), dest->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), user->nick.c_str()); dat->lastnotify = now; } return MOD_RES_DENY; diff --git a/src/modules/m_chanlog.cpp b/src/modules/m_chanlog.cpp index 826c6f32f..e78a4dd47 100644 --- a/src/modules/m_chanlog.cpp +++ b/src/modules/m_chanlog.cpp @@ -84,7 +84,7 @@ class ModuleChanLog : public Module Channel *c = ServerInstance->FindChan(it->second); if (c) { - c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf); + c->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "PRIVMSG %s :%s", c->name.c_str(), buf); ServerInstance->PI->SendChannelPrivmsg(c, 0, buf); } @@ -148,7 +148,7 @@ class ChannelLogStream : public LogStream char buf[MAXBUF]; snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str()); - c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf); + c->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "PRIVMSG %s :%s", c->name.c_str(), buf); ServerInstance->PI->SendChannelPrivmsg(c, 0, buf); Logging = false; } diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index e3de63325..309499ff5 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -53,7 +53,7 @@ class CommandCheck : public Command CmdResult Handle (const std::vector<std::string> ¶meters, User *user) { - if (parameters.size() > 1 && parameters[1] != ServerInstance->Config->ServerName) + if (parameters.size() > 1 && parameters[1] != ServerInstance->Config->ServerName.c_str()) return CMD_SUCCESS; User *targuser; diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp index d13dc1e0a..b676fa681 100644 --- a/src/modules/m_connectban.cpp +++ b/src/modules/m_connectban.cpp @@ -90,7 +90,7 @@ class ModuleConnectBan : public Module if (i->second >= threshold) { // Create zline for set duration. - ZLine* zl = new ZLine(ServerInstance->Time(), banduration, ServerInstance->Config->ServerName, "Connect flooding", u->GetCIDRMask(range)); + ZLine* zl = new ZLine(ServerInstance->Time(), banduration, ServerInstance->Config->ServerName.c_str(), "Connect flooding", u->GetCIDRMask(range)); if (ServerInstance->XLines->AddLine(zl,NULL)) ServerInstance->XLines->ApplyLines(); else diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index cb32ede78..73d5316b5 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -125,7 +125,7 @@ class DNSBLResolver : public Resolver } case DNSBLConfEntry::I_KLINE: { - KLine* kl = new KLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(), + KLine* kl = new KLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(), "*", them->GetIPString()); if (ServerInstance->XLines->AddLine(kl,NULL)) { @@ -139,7 +139,7 @@ class DNSBLResolver : public Resolver } case DNSBLConfEntry::I_GLINE: { - GLine* gl = new GLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(), + GLine* gl = new GLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(), "*", them->GetIPString()); if (ServerInstance->XLines->AddLine(gl,NULL)) { @@ -153,7 +153,7 @@ class DNSBLResolver : public Resolver } case DNSBLConfEntry::I_ZLINE: { - ZLine* zl = new ZLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(), + ZLine* zl = new ZLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(), them->GetIPString()); if (ServerInstance->XLines->AddLine(zl,NULL)) { @@ -378,12 +378,12 @@ class ModuleDNSBL : public Module total_hits += (*i)->stats_hits; total_misses += (*i)->stats_misses; - results.push_back(std::string(ServerInstance->Config->ServerName) + " 304 " + user->nick + " :DNSBLSTATS DNSbl \"" + (*i)->name + "\" had " + + results.push_back(std::string(ServerInstance->Config->ServerName.c_str()) + " 304 " + user->nick + " :DNSBLSTATS DNSbl \"" + (*i)->name + "\" had " + ConvToStr((*i)->stats_hits) + " hits and " + ConvToStr((*i)->stats_misses) + " misses"); } - results.push_back(std::string(ServerInstance->Config->ServerName) + " 304 " + user->nick + " :DNSBLSTATS Total hits: " + ConvToStr(total_hits)); - results.push_back(std::string(ServerInstance->Config->ServerName) + " 304 " + user->nick + " :DNSBLSTATS Total misses: " + ConvToStr(total_misses)); + results.push_back(std::string(ServerInstance->Config->ServerName.c_str()) + " 304 " + user->nick + " :DNSBLSTATS Total hits: " + ConvToStr(total_hits)); + results.push_back(std::string(ServerInstance->Config->ServerName.c_str()) + " 304 " + user->nick + " :DNSBLSTATS Total misses: " + ConvToStr(total_misses)); return MOD_RES_PASSTHRU; } diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index b6dbee4ea..ebb5a0038 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -310,7 +310,7 @@ ModResult FilterBase::OnUserPreNotice(User* user,void* dest,int target_type, std } if (f->action == "gline") { - GLine* gl = new GLine(ServerInstance->Time(), f->gline_time, ServerInstance->Config->ServerName, f->reason.c_str(), "*", user->GetIPString()); + GLine* gl = new GLine(ServerInstance->Time(), f->gline_time, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString()); if (ServerInstance->XLines->AddLine(gl,NULL)) { ServerInstance->XLines->ApplyLines(); @@ -399,7 +399,7 @@ ModResult FilterBase::OnPreCommand(std::string &command, std::vector<std::string if (f->action == "gline") { /* Note: We gline *@IP so that if their host doesnt resolve the gline still applies. */ - GLine* gl = new GLine(ServerInstance->Time(), f->gline_time, ServerInstance->Config->ServerName, f->reason.c_str(), "*", user->GetIPString()); + GLine* gl = new GLine(ServerInstance->Time(), f->gline_time, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString()); if (ServerInstance->XLines->AddLine(gl,NULL)) { ServerInstance->XLines->ApplyLines(); diff --git a/src/modules/m_globalload.cpp b/src/modules/m_globalload.cpp index 348984e14..636b9f4e4 100644 --- a/src/modules/m_globalload.cpp +++ b/src/modules/m_globalload.cpp @@ -30,7 +30,7 @@ class CommandGloadmodule : public Command { std::string servername = parameters.size() > 1 ? parameters[1] : "*"; - if (InspIRCd::Match(ServerInstance->Config->ServerName, servername)) + if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername)) { if (ServerInstance->Modules->Load(parameters[0].c_str())) { @@ -68,7 +68,7 @@ class CommandGunloadmodule : public Command { std::string servername = parameters.size() > 1 ? parameters[1] : "*"; - if (InspIRCd::Match(ServerInstance->Config->ServerName, servername)) + if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername)) { if (ServerInstance->Modules->Unload(parameters[0].c_str())) { @@ -106,7 +106,7 @@ class CommandGreloadmodule : public Command { std::string servername = parameters.size() > 1 ? parameters[1] : "*"; - if (InspIRCd::Match(ServerInstance->Config->ServerName, servername)) + if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername)) { bool ok = true; if (!ServerInstance->Modules->Unload(parameters[0].c_str())) diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp index 2520cbfcf..54e221019 100644 --- a/src/modules/m_joinflood.cpp +++ b/src/modules/m_joinflood.cpp @@ -235,7 +235,7 @@ class ModuleJoinFlood : public Module { f->clear(); f->lock(); - memb->chan->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :This channel has been closed to new users for 60 seconds because there have been more than %d joins in %d seconds.", memb->chan->name.c_str(), f->joins, f->secs); + memb->chan->WriteChannelWithServ((char*)ServerInstance->Config->ServerName.c_str(), "NOTICE %s :This channel has been closed to new users for 60 seconds because there have been more than %d joins in %d seconds.", memb->chan->name.c_str(), f->joins, f->secs); } } } diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp index 28b3b1c50..a266d0aa5 100644 --- a/src/modules/m_knock.cpp +++ b/src/modules/m_knock.cpp @@ -61,7 +61,7 @@ class CommandKnock : public Command } line = line + parameters[parameters.size()-1]; - c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), line.c_str()); + c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName.c_str(), "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), line.c_str()); user->WriteServ("NOTICE %s :KNOCKing on %s", user->nick.c_str(), c->name.c_str()); return CMD_SUCCESS; } diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index 4e6dca5b9..d4b07b0c4 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -230,7 +230,7 @@ class ModuleNickFlood : public Module { f->clear(); f->lock(); - channel->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :No nick changes are allowed for 60 seconds because there have been more than %d nick changes in %d seconds.", channel->name.c_str(), f->nicks, f->secs); + channel->WriteChannelWithServ((char*)ServerInstance->Config->ServerName.c_str(), "NOTICE %s :No nick changes are allowed for 60 seconds because there have been more than %d nick changes in %d seconds.", channel->name.c_str(), f->nicks, f->secs); return MOD_RES_DENY; } } diff --git a/src/modules/m_ojoin.cpp b/src/modules/m_ojoin.cpp index c4ba99779..5bd9e3f91 100644 --- a/src/modules/m_ojoin.cpp +++ b/src/modules/m_ojoin.cpp @@ -70,7 +70,7 @@ class CommandOjoin : public Command if (notice) { channel = ServerInstance->FindChan(parameters[0]); - channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s joined on official network business.", + channel->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s joined on official network business.", parameters[0].c_str(), user->nick.c_str()); ServerInstance->PI->SendChannelNotice(channel, 0, std::string(user->nick) + " joined on official network business."); } diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp index 3c45bb37d..8162d45e3 100644 --- a/src/modules/m_override.cpp +++ b/src/modules/m_override.cpp @@ -150,7 +150,7 @@ class ModuleOverride : public Module } if (NoisyOverride) - chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str()); + chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str()); ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +i on "+std::string(cname)); } return MOD_RES_ALLOW; @@ -166,7 +166,7 @@ class ModuleOverride : public Module } if (NoisyOverride) - chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str()); + chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str()); ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +k on "+std::string(cname)); return MOD_RES_ALLOW; } @@ -181,7 +181,7 @@ class ModuleOverride : public Module } if (NoisyOverride) - chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str()); + chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str()); ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +l on "+std::string(cname)); return MOD_RES_ALLOW; } @@ -196,7 +196,7 @@ class ModuleOverride : public Module } if (NoisyOverride) - chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str()); + chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str()); ServerInstance->SNO->WriteGlobalSno('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname); return MOD_RES_ALLOW; } diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp index ef60639f4..89565618b 100644 --- a/src/modules/m_remove.cpp +++ b/src/modules/m_remove.cpp @@ -103,7 +103,7 @@ class RemoveBase : public Command /* Build up the part reason string. */ reason = std::string("Removed by ") + user->nick + ": " + reasonparam; - channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name.c_str(), user->nick.c_str(), target->nick.c_str()); + channel->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s removed %s from the channel", channel->name.c_str(), user->nick.c_str(), target->nick.c_str()); target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick.c_str(), user->nick.c_str(), channel->name.c_str(), reasonparam.c_str()); if (!channel->PartUser(target, reason)) diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index 8bad04f29..31b382a22 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -75,7 +75,7 @@ class RLine : public XLine void Apply(User* u) { if (ZlineOnMatch) { - background_zlines.push_back(new ZLine(ServerInstance->Time(), duration ? expiry - ServerInstance->Time() : 0, ServerInstance->Config->ServerName, reason.c_str(), u->GetIPString())); + background_zlines.push_back(new ZLine(ServerInstance->Time(), duration ? expiry - ServerInstance->Time() : 0, ServerInstance->Config->ServerName.c_str(), reason.c_str(), u->GetIPString())); } DefaultApply(u, "R", false); } diff --git a/src/modules/m_servprotect.cpp b/src/modules/m_servprotect.cpp index 96e54f8e7..4103de81b 100644 --- a/src/modules/m_servprotect.cpp +++ b/src/modules/m_servprotect.cpp @@ -87,7 +87,7 @@ class ModuleServProtectMode : public Module if (u->IsModeSet('k') && ServerInstance->Modes->ModeString(u, chan, false).find(mode) != std::string::npos) { /* BZZZT, Denied! */ - user->WriteNumeric(482, "%s %s :You are not permitted to remove privileges from %s services", user->nick.c_str(), chan->name.c_str(), ServerInstance->Config->Network); + user->WriteNumeric(482, "%s %s :You are not permitted to remove privileges from %s services", user->nick.c_str(), chan->name.c_str(), ServerInstance->Config->Network.c_str()); return MOD_RES_DENY; } } @@ -103,7 +103,7 @@ class ModuleServProtectMode : public Module if (dst->IsModeSet('k')) { - src->WriteNumeric(485, "%s :You are not permitted to kill %s services!", src->nick.c_str(), ServerInstance->Config->Network); + src->WriteNumeric(485, "%s :You are not permitted to kill %s services!", src->nick.c_str(), ServerInstance->Config->Network.c_str()); ServerInstance->SNO->WriteGlobalSno('a', std::string(src->nick)+" tried to kill service "+dst->nick+" ("+reason+")"); return MOD_RES_DENY; } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 8b9f40e0b..7d6974cf0 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -91,7 +91,7 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops) return; user->WriteNumeric(364, "%s %s %s :%d %s", user->nick.c_str(),Current->GetName().c_str(), - (Utils->FlatLinks && (!IS_OPER(user))) ? ServerInstance->Config->ServerName : Parent.c_str(), + (Utils->FlatLinks && (!IS_OPER(user))) ? ServerInstance->Config->ServerName.c_str() : Parent.c_str(), (Utils->FlatLinks && (!IS_OPER(user))) ? 0 : hops, Current->GetDesc().c_str()); } @@ -829,7 +829,7 @@ void ModuleSpanningTree::OnAddLine(User* user, XLine *x) char data[MAXBUF]; snprintf(data,MAXBUF,"%s %s %s %lu %lu :%s", x->type.c_str(), x->Displayable(), - ServerInstance->Config->ServerName, (unsigned long)x->set_time, (unsigned long)x->duration, x->reason.c_str()); + ServerInstance->Config->ServerName.c_str(), (unsigned long)x->set_time, (unsigned long)x->duration, x->reason.c_str()); parameterlist params; params.push_back(data); diff --git a/src/modules/m_spanningtree/opertype.cpp b/src/modules/m_spanningtree/opertype.cpp index 38b621fb5..dc9c0064f 100644 --- a/src/modules/m_spanningtree/opertype.cpp +++ b/src/modules/m_spanningtree/opertype.cpp @@ -47,10 +47,7 @@ bool TreeSocket::OperType(const std::string &prefix, parameterlist ¶ms) * If quiet bursts are enabled, and server is bursting or silent uline (i.e. services), * then do nothing. -- w00t */ - if ( - remoteserver->bursting || - ServerInstance->SilentULine(ServerInstance->FindServerNamePtr(u->server)) - ) + if (remoteserver->bursting || ServerInstance->SilentULine(u->server)) { dosend = false; } diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index 147445c0c..7d09d939f 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -170,13 +170,13 @@ bool ModuleSpanningTree::HandleMap(const std::vector<std::string>& parameters, U { // terminate the string at maxnamew characters names[100 * t + maxnamew] = '\0'; - ServerInstance->DumpText(user, ":%s %d %s :%s %s", ServerInstance->Config->ServerName, + ServerInstance->DumpText(user, ":%s %d %s :%s %s", ServerInstance->Config->ServerName.c_str(), RPL_MAP, user->nick.c_str(), names + 100 * t, stats + 50 * t); } ServerInstance->DumpText(user, ":%s %d %s :%d server%s and %d user%s, average %.2f users per server", - ServerInstance->Config->ServerName, RPL_MAPUSERS, user->nick.c_str(), + ServerInstance->Config->ServerName.c_str(), RPL_MAPUSERS, user->nick.c_str(), line, (line > 1 ? "s" : ""), totusers, (totusers > 1 ? "s" : ""), avg_users); - ServerInstance->DumpText(user, ":%s %d %s :End of /MAP", ServerInstance->Config->ServerName, + ServerInstance->DumpText(user, ":%s %d %s :End of /MAP", ServerInstance->Config->ServerName.c_str(), RPL_ENDMAP, user->nick.c_str()); delete[] names; diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp index 96ca2236d..6279564df 100644 --- a/src/modules/m_spanningtree/uid.cpp +++ b/src/modules/m_spanningtree/uid.cpp @@ -99,7 +99,7 @@ bool TreeSocket::ParseUID(const std::string &source, parameterlist ¶ms) _new->nick.assign(params[2], 0, MAXBUF); _new->host.assign(params[3], 0, 64); _new->dhost.assign(params[4], 0, 64); - _new->server = ServerInstance->FindServerNamePtr(remoteserver->GetName().c_str()); + _new->server = remoteserver->GetName(); _new->ident.assign(params[5], 0, MAXBUF); _new->fullname.assign(params[params.size() - 1], 0, MAXBUF); _new->registered = REG_ALL; diff --git a/src/modules/m_sqllog.cpp b/src/modules/m_sqllog.cpp index 73f53f8c0..c70c1bf7a 100644 --- a/src/modules/m_sqllog.cpp +++ b/src/modules/m_sqllog.cpp @@ -292,7 +292,7 @@ class ModuleSQLLog : public Module virtual void OnLoadModule(Module* mod, const std::string &name) { - AddLogEntry(LT_LOADMODULE,name,ServerInstance->Config->ServerName, ServerInstance->Config->ServerName); + AddLogEntry(LT_LOADMODULE,name,ServerInstance->Config->ServerName.c_str(), ServerInstance->Config->ServerName.c_str()); } virtual Version GetVersion() diff --git a/src/modules/m_testnet.cpp b/src/modules/m_testnet.cpp index a4bdfc561..6a0cfa303 100644 --- a/src/modules/m_testnet.cpp +++ b/src/modules/m_testnet.cpp @@ -51,7 +51,7 @@ class ModuleTest : public Module public: ModuleTest() : cmd(this) { - if (!strstr(ServerInstance->Config->ServerName, ".test")) + if (!strstr(ServerInstance->Config->ServerName.c_str(), ".test")) throw ModuleException("Don't load modules without reading their descriptions!"); ServerInstance->AddCommand(&cmd); } diff --git a/src/modules/m_uninvite.cpp b/src/modules/m_uninvite.cpp index c44e15511..1d7941b57 100644 --- a/src/modules/m_uninvite.cpp +++ b/src/modules/m_uninvite.cpp @@ -70,7 +70,7 @@ class CommandUninvite : public Command u->RemoveInvite(xname); user->WriteNumeric(494, "%s %s %s :Uninvited", user->nick.c_str(), c->name.c_str(), u->nick.c_str()); u->WriteNumeric(493, "%s :You were uninvited from %s by %s", u->nick.c_str(), c->name.c_str(), user->nick.c_str()); - c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s uninvited %s.", c->name.c_str(), user->nick.c_str(), u->nick.c_str()); + c->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :*** %s uninvited %s.", c->name.c_str(), user->nick.c_str(), u->nick.c_str()); return CMD_SUCCESS; } diff --git a/src/modules/m_xline_db.cpp b/src/modules/m_xline_db.cpp index 991d803d6..329fc8e27 100644 --- a/src/modules/m_xline_db.cpp +++ b/src/modules/m_xline_db.cpp @@ -117,7 +117,7 @@ class ModuleXLineDB : public Module { line = (*i); fprintf(f, "LINE %s %s %s %lu %lu :%s\n", line->type.c_str(), line->Displayable(), - ServerInstance->Config->ServerName, (unsigned long)line->set_time, (unsigned long)line->duration, line->reason.c_str()); + ServerInstance->Config->ServerName.c_str(), (unsigned long)line->set_time, (unsigned long)line->duration, line->reason.c_str()); } ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Finished writing XLines. Checking for error.."); diff --git a/src/server.cpp b/src/server.cpp index cea92ac51..e5546654e 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -68,13 +68,13 @@ void InspIRCd::RehashServer() std::string InspIRCd::GetVersionString() { char versiondata[MAXBUF]; - if (*Config->CustomVersion) + if (!Config->CustomVersion.empty()) { - snprintf(versiondata,MAXBUF,"InspIRCd-2.0 %s :%s",Config->ServerName,Config->CustomVersion); + snprintf(versiondata,MAXBUF,"InspIRCd-2.0 %s :%s",Config->ServerName.c_str(),Config->CustomVersion.c_str()); } else { - snprintf(versiondata,MAXBUF,"InspIRCd-2.0 %s :%s (%s) [FLAGS=%s,%s,%s]",Config->ServerName,SYSTEM,VERSION,REVISION,SE->GetName().c_str(),Config->sid); + snprintf(versiondata,MAXBUF,"InspIRCd-2.0 %s :%s (%s) [FLAGS=%s,%s,%s]",Config->ServerName.c_str(),SYSTEM,VERSION,REVISION,SE->GetName().c_str(),Config->sid.c_str()); } return versiondata; } @@ -96,38 +96,6 @@ std::string InspIRCd::GetRevision() return REVISION; } -void InspIRCd::AddServerName(const std::string &servername) -{ - servernamelist::iterator itr = servernames.begin(); - for(; itr != servernames.end(); ++itr) - if(**itr == servername) - return; - - std::string * ns = new std::string(servername); - servernames.push_back(ns); -} - -const char* InspIRCd::FindServerNamePtr(const std::string &servername) -{ - servernamelist::iterator itr = servernames.begin(); - for(; itr != servernames.end(); ++itr) - if(**itr == servername) - return (*itr)->c_str(); - - servernames.push_back(new std::string(servername)); - itr = --servernames.end(); - return (*itr)->c_str(); -} - -bool InspIRCd::FindServerName(const std::string &servername) -{ - servernamelist::iterator itr = servernames.begin(); - for(; itr != servernames.end(); ++itr) - if(**itr == servername) - return true; - return false; -} - void InspIRCd::IncrementUID(int pos) { /* diff --git a/src/socket.cpp b/src/socket.cpp index b719ebe82..00be4250b 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -72,13 +72,12 @@ bool InspIRCd::BindSocket(int sockfd, int port, const char* addr, bool dolisten) } // Open a TCP Socket -int irc::sockets::OpenTCPSocket(const char* addr, int socktype) +int irc::sockets::OpenTCPSocket(const std::string& addr, int socktype) { int sockfd; int on = 1; - addr = addr; struct linger linger = { 0, 0 }; - if (!*addr) + if (addr.empty()) { #ifdef IPV6 sockfd = socket (PF_INET6, socktype, 0); @@ -86,7 +85,7 @@ int irc::sockets::OpenTCPSocket(const char* addr, int socktype) #endif sockfd = socket (PF_INET, socktype, 0); } - else if (strchr(addr,':')) + else if (addr.find(':') != std::string::npos) sockfd = socket (PF_INET6, socktype, 0); else sockfd = socket (PF_INET, socktype, 0); @@ -186,10 +185,10 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports) return bound; } -bool irc::sockets::aptosa(const char* addr, int port, irc::sockets::sockaddrs* sa) +bool irc::sockets::aptosa(const std::string& addr, int port, irc::sockets::sockaddrs* sa) { memset(sa, 0, sizeof(*sa)); - if (!addr || !*addr) + if (addr.empty()) { #ifdef IPV6 sa->in6.sin6_family = AF_INET6; @@ -200,13 +199,13 @@ bool irc::sockets::aptosa(const char* addr, int port, irc::sockets::sockaddrs* s #endif return true; } - else if (inet_pton(AF_INET, addr, &sa->in4.sin_addr) > 0) + else if (inet_pton(AF_INET, addr.c_str(), &sa->in4.sin_addr) > 0) { sa->in4.sin_family = AF_INET; sa->in4.sin_port = htons(port); return true; } - else if (inet_pton(AF_INET6, addr, &sa->in6.sin6_addr) > 0) + else if (inet_pton(AF_INET6, addr.c_str(), &sa->in6.sin6_addr) > 0) { sa->in6.sin6_family = AF_INET6; sa->in6.sin6_port = htons(port); diff --git a/src/stats.cpp b/src/stats.cpp index b7b92d9a6..448d6deee 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -19,7 +19,7 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results) { std::string sn(this->Config->ServerName); - if (!user->HasPrivPermission("servers/auspex") && !strchr(this->Config->UserStats, statschar)) + if (!user->HasPrivPermission("servers/auspex") && Config->UserStats.find(statschar) == std::string::npos) { this->SNO->WriteToSnoMask('t', "%s '%c' denied for %s (%s@%s)", diff --git a/src/usermanager.cpp b/src/usermanager.cpp index e4bc3254e..2eebb1ed0 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -63,7 +63,7 @@ void UserManager::AddUser(int socket, ClientListenSocket* via, irc::sockets::soc /* The users default nick is their UUID */ New->nick.assign(New->uuid, 0, ServerInstance->Config->Limits.NickMax); - New->server = ServerInstance->FindServerNamePtr(ServerInstance->Config->ServerName); + New->server = ServerInstance->Config->ServerName; New->ident.assign("unknown"); New->registered = REG_NONE; @@ -117,8 +117,8 @@ void UserManager::AddUser(int socket, ClientListenSocket* via, irc::sockets::soc { /* user banned */ ServerInstance->Logs->Log("BANCACHE", DEBUG, std::string("BanCache: Positive hit for ") + New->GetIPString()); - if (*ServerInstance->Config->MoronBanner) - New->WriteServ("NOTICE %s :*** %s", New->nick.c_str(), ServerInstance->Config->MoronBanner); + if (!ServerInstance->Config->MoronBanner.empty()) + New->WriteServ("NOTICE %s :*** %s", New->nick.c_str(), ServerInstance->Config->MoronBanner.c_str()); this->QuitUser(New, b->Reason); return; } @@ -421,7 +421,7 @@ void UserManager::ServerNoticeAll(const char* text, ...) vsnprintf(textbuffer, MAXBUF, text, argsPtr); va_end(argsPtr); - snprintf(formatbuffer,MAXBUF,"NOTICE $%s :%s", ServerInstance->Config->ServerName, textbuffer); + snprintf(formatbuffer,MAXBUF,"NOTICE $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer); for (std::vector<User*>::const_iterator i = local_users.begin(); i != local_users.end(); i++) { @@ -442,7 +442,7 @@ void UserManager::ServerPrivmsgAll(const char* text, ...) vsnprintf(textbuffer, MAXBUF, text, argsPtr); va_end(argsPtr); - snprintf(formatbuffer,MAXBUF,"PRIVMSG $%s :%s", ServerInstance->Config->ServerName, textbuffer); + snprintf(formatbuffer,MAXBUF,"PRIVMSG $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer); for (std::vector<User*>::const_iterator i = local_users.begin(); i != local_users.end(); i++) { diff --git a/src/userprocess.cpp b/src/userprocess.cpp index 4da623590..d4de29075 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -78,7 +78,7 @@ void InspIRCd::DoBackgroundUserStuff() continue; } - curr->Write("PING :%s",this->Config->ServerName); + curr->Write("PING :%s",this->Config->ServerName.c_str()); curr->lastping = 0; curr->nping = TIME +curr->MyClass->GetPingTime(); } diff --git a/src/users.cpp b/src/users.cpp index 222bde9e9..33931fd45 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -207,7 +207,7 @@ void User::DecrementModes() User::User(const std::string &uid) { - server = ServerInstance->FindServerNamePtr(ServerInstance->Config->ServerName); + server = ServerInstance->Config->ServerName; age = ServerInstance->Time(); Penalty = 0; lastping = signon = idle_lastmsg = nping = registered = 0; @@ -839,11 +839,11 @@ void User::FullConnect() if (this->CheckLines()) return; - this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network); - this->WriteNumeric(RPL_WELCOME, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick.c_str(), ServerInstance->Config->Network, this->nick.c_str(), this->ident.c_str(), this->host.c_str()); - this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-2.0",this->nick.c_str(),ServerInstance->Config->ServerName); + this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network.c_str()); + this->WriteNumeric(RPL_WELCOME, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick.c_str(), ServerInstance->Config->Network.c_str(), this->nick.c_str(), this->ident.c_str(), this->host.c_str()); + this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-2.0",this->nick.c_str(),ServerInstance->Config->ServerName.c_str()); this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__); - this->WriteNumeric(RPL_SERVERVERSION, "%s %s InspIRCd-2.0 %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str()); + this->WriteNumeric(RPL_SERVERVERSION, "%s %s InspIRCd-2.0 %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName.c_str(), ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str()); ServerInstance->Config->Send005(this); this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str()); @@ -1118,7 +1118,7 @@ void User::Write(const char *text, ...) void User::WriteServ(const std::string& text) { - this->Write(":%s %s",ServerInstance->Config->ServerName,text.c_str()); + this->Write(":%s %s",ServerInstance->Config->ServerName.c_str(),text.c_str()); } /** WriteServ() @@ -1159,7 +1159,7 @@ void User::WriteNumeric(unsigned int numeric, const std::string &text) if (MOD_RESULT == MOD_RES_DENY) return; - snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str()); + snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName.c_str(), numeric, text.c_str()); this->Write(std::string(textbuffer)); } @@ -1564,7 +1564,7 @@ void User::SplitChanList(User* dest, const std::string &cl) prefix << this->nick << " " << dest->nick << " :"; line = prefix.str(); - int namelen = strlen(ServerInstance->Config->ServerName) + 6; + int namelen = ServerInstance->Config->ServerName.length() + 6; for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1) { @@ -1745,7 +1745,7 @@ void User::ShowMOTD() this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str()); return; } - this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName); + this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName.c_str()); for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++) this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str()); @@ -1761,7 +1761,7 @@ void User::ShowRULES() return; } - this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName); + this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName.c_str()); for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++) this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str()); @@ -1782,19 +1782,19 @@ void User::DecreasePenalty(int decrease) void FakeUser::SetFakeServer(std::string name) { this->nick = name; - this->server = nick.c_str(); + this->server = name; } const std::string FakeUser::GetFullHost() { - if (*ServerInstance->Config->HideWhoisServer) + if (ServerInstance->Config->HideWhoisServer.empty()) return ServerInstance->Config->HideWhoisServer; return nick; } const std::string FakeUser::GetFullRealHost() { - if (*ServerInstance->Config->HideWhoisServer) + if (!ServerInstance->Config->HideWhoisServer.empty()) return ServerInstance->Config->HideWhoisServer; return nick; } diff --git a/src/whois.cpp b/src/whois.cpp index 3f0343343..290566446 100644 --- a/src/whois.cpp +++ b/src/whois.cpp @@ -34,9 +34,9 @@ void InspIRCd::DoWhois(User* user, User* dest,unsigned long signon, unsigned lon user->SplitChanList(dest,scl); } } - if (user != dest && *this->Config->HideWhoisServer && !user->HasPrivPermission("servers/auspex")) + if (user != dest && !this->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex")) { - this->SendWhoisLine(user, dest, 312, "%s %s %s :%s",user->nick.c_str(), dest->nick.c_str(), this->Config->HideWhoisServer, this->Config->Network); + this->SendWhoisLine(user, dest, 312, "%s %s %s :%s",user->nick.c_str(), dest->nick.c_str(), this->Config->HideWhoisServer.c_str(), this->Config->Network.c_str()); } else { @@ -53,7 +53,7 @@ void InspIRCd::DoWhois(User* user, User* dest,unsigned long signon, unsigned lon if (this->Config->GenericOper) this->SendWhoisLine(user, dest, 313, "%s %s :is an IRC operator",user->nick.c_str(), dest->nick.c_str()); else - this->SendWhoisLine(user, dest, 313, "%s %s :is %s %s on %s",user->nick.c_str(), dest->nick.c_str(), (strchr("AEIOUaeiou",dest->oper[0]) ? "an" : "a"),irc::Spacify(dest->oper.c_str()), this->Config->Network); + this->SendWhoisLine(user, dest, 313, "%s %s :is %s %s on %s",user->nick.c_str(), dest->nick.c_str(), (strchr("AEIOUaeiou",dest->oper[0]) ? "an" : "a"),irc::Spacify(dest->oper.c_str()), this->Config->Network.c_str()); } if (user == dest || user->HasPrivPermission("users/auspex")) diff --git a/src/xline.cpp b/src/xline.cpp index 2fa6dda00..5df0281c9 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -444,8 +444,8 @@ void XLine::DefaultApply(User* u, const std::string &line, bool bancache) { char sreason[MAXBUF]; snprintf(sreason, MAXBUF, "%s-Lined: %s", line.c_str(), this->reason.c_str()); - if (*ServerInstance->Config->MoronBanner) - u->WriteServ("NOTICE %s :*** %s", u->nick.c_str(), ServerInstance->Config->MoronBanner); + if (!ServerInstance->Config->MoronBanner.empty()) + u->WriteServ("NOTICE %s :*** %s", u->nick.c_str(), ServerInstance->Config->MoronBanner.c_str()); if (ServerInstance->Config->HideBans) ServerInstance->Users->QuitUser(u, line + "-Lined", sreason); |