diff options
| author | Adam <Adam@anope.org> | 2015-01-05 16:31:09 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2015-01-05 19:00:51 -0500 |
| commit | d79d8e2608e304760c42bdf87502e3bc51781b88 (patch) | |
| tree | 179913b8b328f88d52d84c3453fceb28a2d63422 /src | |
| parent | 8ab1c71d7dc7a0d47e5711dc72e3fc9c3ee850bb (diff) | |
| parent | c46ec39e5088119cd21f5f7e16e64e61a876ca20 (diff) | |
Merge branch '2.0' into 2.1
Conflicts:
CMakeLists.txt
include/modules.h
include/serialize.h
modules/commands/bs_assign.cpp
modules/commands/bs_badwords.cpp
modules/commands/bs_bot.cpp
modules/commands/bs_control.cpp
modules/commands/bs_kick.cpp
modules/commands/cs_access.cpp
modules/commands/cs_akick.cpp
modules/commands/cs_drop.cpp
modules/commands/cs_entrymsg.cpp
modules/commands/cs_flags.cpp
modules/commands/cs_info.cpp
modules/commands/cs_invite.cpp
modules/commands/cs_kick.cpp
modules/commands/cs_mode.cpp
modules/commands/cs_register.cpp
modules/commands/cs_seen.cpp
modules/commands/cs_set.cpp
modules/commands/cs_suspend.cpp
modules/commands/cs_topic.cpp
modules/commands/cs_unban.cpp
modules/commands/cs_xop.cpp
modules/commands/hs_del.cpp
modules/commands/hs_list.cpp
modules/commands/hs_request.cpp
modules/commands/ms_ignore.cpp
modules/commands/ms_send.cpp
modules/commands/ns_recover.cpp
modules/commands/ns_register.cpp
modules/commands/ns_suspend.cpp
modules/commands/os_dns.cpp
modules/commands/os_noop.cpp
modules/commands/os_oper.cpp
modules/commands/os_session.cpp
modules/database/db_sql_live.cpp
modules/encryption/enc_bcrypt.cpp
modules/extra/m_ldap_authentication.cpp
modules/extra/m_ldap_oper.cpp
modules/fantasy.cpp
modules/m_dnsbl.cpp
modules/m_sasl.cpp
modules/protocol/hybrid.cpp
modules/protocol/inspircd20.cpp
modules/protocol/unreal.cpp
modules/pseudoclients/chanserv.cpp
modules/pseudoclients/nickserv.cpp
modules/webcpanel/pages/chanserv/access.cpp
modules/webcpanel/webcpanel.cpp
modules/webcpanel/webcpanel.h
src/command.cpp
src/messages.cpp
src/modulemanager.cpp
src/regchannel.cpp
src/serialize.cpp
Diffstat (limited to 'src')
| -rw-r--r-- | src/channels.cpp | 47 | ||||
| -rw-r--r-- | src/command.cpp | 43 | ||||
| -rw-r--r-- | src/init.cpp | 25 | ||||
| -rw-r--r-- | src/messages.cpp | 14 | ||||
| -rw-r--r-- | src/protocol.cpp | 11 | ||||
| -rw-r--r-- | src/servers.cpp | 2 | ||||
| -rw-r--r-- | src/uplink.cpp | 2 | ||||
| -rw-r--r-- | src/users.cpp | 2 |
8 files changed, 90 insertions, 56 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index 2d01ad703..7972dca6b 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -103,7 +103,7 @@ void Channel::CheckModes() return; /* Check for mode bouncing */ - if (this->server_modecount >= 3 && this->chanserv_modecount >= 3) + if (this->chanserv_modetime == Anope::CurTime && this->server_modetime == Anope::CurTime && this->server_modecount >= 3 && this->chanserv_modecount >= 3) { Log() << "Warning: unable to set modes on channel " << this->name << ". Are your servers' U:lines configured correctly?"; this->bouncy_modes = 1; @@ -197,9 +197,9 @@ size_t Channel::HasMode(const Anope::string &mname, const Anope::string ¶m) { if (param.empty()) return modes.count(mname); - std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> its = this->GetModeList(mname); - for (; its.first != its.second; ++its.first) - if (its.first->second.equals_ci(param)) + std::vector<Anope::string> v = this->GetModeList(mname); + for (unsigned int i = 0; i < v.size(); ++i) + if (v[i].equals_ci(param)) return 1; return 0; } @@ -235,12 +235,20 @@ const Channel::ModeList &Channel::GetModes() const return this->modes; } -std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> Channel::GetModeList(const Anope::string &mname) +template<typename F, typename S> +struct second { - Channel::ModeList::iterator it = this->modes.find(mname), it_end = it; - if (it != this->modes.end()) - it_end = this->modes.upper_bound(mname); - return std::make_pair(it, it_end); + S operator()(const std::pair<F, S> &p) + { + return p.second; + } +}; + +std::vector<Anope::string> Channel::GetModeList(const Anope::string &mname) +{ + std::vector<Anope::string> r; + std::transform(modes.lower_bound(mname), modes.upper_bound(mname), std::back_inserter(r), second<Anope::string, Anope::string>()); + return r; } void Channel::SetModeInternal(const MessageSource &setter, ChannelMode *ocm, const Anope::string &oparam, bool enforce_mlock) @@ -357,11 +365,10 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *ocm, if (cm->type == MODE_LIST) { - std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> its = this->GetModeList(cm->name); - for (; its.first != its.second; ++its.first) - if (param.equals_ci(its.first->second)) + for (Channel::ModeList::iterator it = modes.lower_bound(cm->name), it_end = modes.upper_bound(cm->name); it != it_end; ++it) + if (param.equals_ci(it->second)) { - this->modes.erase(its.first); + this->modes.erase(it); break; } } @@ -707,11 +714,10 @@ bool Channel::MatchesList(User *u, const Anope::string &mode) if (!this->HasMode(mode)) return false; - - std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> m = this->GetModeList(mode); - for (; m.first != m.second; ++m.first) + std::vector<Anope::string> v = this->GetModeList(mode); + for (unsigned i = 0; i < v.size(); ++i) { - Entry e(mode, m.first->second); + Entry e(mode, v[i]); if (e.Matches(u)) return true; } @@ -866,11 +872,10 @@ bool Channel::Unban(User *u, const Anope::string &mode, bool full) bool ret = false; - std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = this->GetModeList(mode); - for (; bans.first != bans.second;) + std::vector<Anope::string> v = this->GetModeList(mode); + for (unsigned int i = 0; i < v.size(); ++i) { - Entry ban(mode, bans.first->second); - ++bans.first; + Entry ban(mode, v[i]); if (ban.Matches(u, full)) { this->RemoveMode(NULL, mode, ban.GetMask()); diff --git a/src/command.cpp b/src/command.cpp index c387ddaab..f7de4ccec 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -223,18 +223,6 @@ void Command::Run(CommandSource &source, const Anope::string &message) return; } - if (c->RequireUser() && !source.GetUser()) - return; - - // Command requires registered users only - if (!c->AllowUnregistered() && !source.nc) - { - source.Reply(_("Password authentication required for that command.")); - if (source.GetUser()) - Log(LOG_NORMAL, "access_denied_unreg", source.service) << "Access denied for unregistered user " << source.GetUser()->GetMask() << " with command " << it->first; - return; - } - for (unsigned i = 0, j = params.size() - (count - 1); i < j; ++i) params.erase(params.begin()); @@ -244,17 +232,34 @@ void Command::Run(CommandSource &source, const Anope::string &message) params.erase(params.begin() + c->max_params); } - source.command = it->first; + c->Run(source, it->first, info, params); +} + +void Command::Run(CommandSource &source, const Anope::string &cmdname, const CommandInfo &info, std::vector<Anope::string> ¶ms) +{ + if (this->RequireUser() && !source.GetUser()) + return; + + // Command requires registered users only + if (!this->AllowUnregistered() && !source.nc) + { + source.Reply(_("Password authentication required for that command.")); + if (source.GetUser()) + Log(LOG_NORMAL, "access_denied_unreg", source.service) << "Access denied for unregistered user " << source.GetUser()->GetMask() << " with command " << cmdname; + return; + } + + source.command = cmdname; source.permission = info.permission; EventReturn MOD_RESULT; - MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, c, params); + MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, this, params); if (MOD_RESULT == EVENT_STOP) return; - if (params.size() < c->min_params) + if (params.size() < this->min_params) { - c->OnSyntaxError(source, !params.empty() ? params[params.size() - 1] : ""); + this->OnSyntaxError(source, !params.empty() ? params[params.size() - 1] : ""); return; } @@ -266,12 +271,12 @@ void Command::Run(CommandSource &source, const Anope::string &message) else source.Reply(_("Access denied. You do not have access to command \002{0}\002."), info.permission); if (source.GetUser()) - Log(LOG_NORMAL, "access_denied", source.service) << "Access denied for user " << source.GetUser()->GetMask() << " with command " << it->first; + Log(LOG_NORMAL, "access_denied", source.service) << "Access denied for user " << source.GetUser()->GetMask() << " with command " << cmdname; return; } - c->Execute(source, params); - Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, c, params); + this->Execute(source, params); + Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, this, params); } bool Command::FindCommandFromService(const Anope::string &command_service, ServiceBot* &bot, Anope::string &name) diff --git a/src/init.cpp b/src/init.cpp index 0b381cbf6..7e29b43b0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -102,6 +102,8 @@ bool Anope::AtTerm() return isatty(fileno(stdout)) && isatty(fileno(stdin)) && isatty(fileno(stderr)); } +static void setuidgid(); + void Anope::Fork() { #ifndef _WIN32 @@ -112,6 +114,8 @@ void Anope::Fork() freopen("/dev/null", "w", stderr); setpgid(0, 0); + + setuidgid(); #else FreeConsole(); #endif @@ -418,10 +422,15 @@ void Anope::Init(int ac, char **av) /* If we're root, issue a warning now */ if (!getuid() && !getgid()) { - std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl; - std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl; - std::cerr << " as the root superuser." << std::endl; - sleep(3); + /* If we are configured to setuid later, don't issue a warning */ + Configuration::Block *options = Config->GetBlock("options"); + if (options->Get<Anope::string>("user").empty()) + { + std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl; + std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl; + std::cerr << " as the root superuser." << std::endl; + sleep(3); + } } #endif @@ -431,7 +440,7 @@ void Anope::Init(int ac, char **av) Log(LOG_TERMINAL) << "Using configuration file " << Anope::ConfigDir << "/" << ServicesConf.GetName(); /* Fork to background */ - if (!Anope::NoFork && Anope::AtTerm()) + if (!Anope::NoFork) { /* Install these before fork() - it is possible for the child to * connect and kill() the parent before it is able to install the @@ -522,7 +531,11 @@ void Anope::Init(int ac, char **av) for (int i = 0; i < Config->CountBlock("module"); ++i) ModuleManager::LoadModule(Config->GetBlock("module", i)->Get<Anope::string>("name"), NULL); - setuidgid(); +#ifndef _WIN32 + /* We won't background later, so we should setuid now */ + if (Anope::NoFork) + setuidgid(); +#endif Module *protocol = ModuleManager::FindFirstOf(PROTOCOL); if (protocol == NULL) diff --git a/src/messages.cpp b/src/messages.cpp index a19c71332..6a9945336 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -205,7 +205,7 @@ void Kill::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) bi->OnKill(); } else - u->KillInternal(source.GetSource(), params[1]); + u->KillInternal(source, params[1]); } void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) @@ -391,6 +391,14 @@ void SQuit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) return; } + if (s == Me) + { + if (Me->GetLinks().empty()) + return; + + s = Me->GetLinks().front(); + } + s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); } @@ -417,7 +425,7 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) else { for (Oper *o : Serialize::GetObjects<Oper *>(operblock)) - IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->GetName().c_str(), o->GetType()->GetName().c_str()); + IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->GetName().c_str(), o->GetType()->GetName().replace_all_cs(" ", "_").c_str()); IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); } @@ -425,7 +433,7 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) break; case 'u': { - time_t uptime = Anope::CurTime - Anope::StartTime; + long uptime = static_cast<long>(Anope::CurTime - Anope::StartTime); IRCD->SendNumeric(242, source.GetSource(), ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60); IRCD->SendNumeric(250, source.GetSource(), ":Current users: %d (%d ops); maximum %d", UserListByNick.size(), OperCount, MaxUserCount); IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); diff --git a/src/protocol.cpp b/src/protocol.cpp index d0cb5df68..f71b3f8b5 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -45,14 +45,17 @@ const Anope::string &IRCDProto::GetProtocolName() return this->proto_name; } -static inline char& nextID(char &c) +static inline char nextID(int pos, Anope::string &buf) { + char &c = buf[pos]; if (c == 'Z') c = '0'; else if (c != '9') ++c; - else + else if (pos) c = 'A'; + else + c = '0'; return c; } @@ -66,7 +69,7 @@ Anope::string IRCDProto::UID_Retrieve() do { int current_len = current_uid.length() - 1; - while (current_len >= 0 && nextID(current_uid[current_len--]) == 'A'); + while (current_len >= 0 && nextID(current_len--, current_uid) == 'A'); } while (User::Find(Me->GetSID() + current_uid) != NULL); @@ -85,7 +88,7 @@ Anope::string IRCDProto::SID_Retrieve() do { int current_len = current_sid.length() - 1; - while (current_len >= 0 && nextID(current_sid[current_len--]) == 'A'); + while (current_len >= 0 && nextID(current_len--, current_sid) == 'A'); } while (Server::Find(current_sid) != NULL); diff --git a/src/servers.cpp b/src/servers.cpp index ece923ac5..394d4d6e8 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -292,7 +292,7 @@ void Server::Sync(bool sync_links) Event::OnUplinkSync(&Event::UplinkSync::OnUplinkSync, this); - if (!Anope::NoFork && Anope::AtTerm()) + if (!Anope::NoFork) { Log(LOG_TERMINAL) << "Successfully linked, launching into background..."; Anope::Fork(); diff --git a/src/uplink.cpp b/src/uplink.cpp index f886b3f81..214de53be 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -70,7 +70,7 @@ UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[Anope::CurrentUplink]. UplinkSocket::~UplinkSocket() { - if (!error) + if (!error && !Anope::Quitting) { this->OnError(""); Module *protocol = ModuleManager::FindFirstOf(PROTOCOL); diff --git a/src/users.cpp b/src/users.cpp index ff81a3017..850cd8de8 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -832,7 +832,7 @@ bool User::BadPassword() this->invalid_pw_time = Anope::CurTime; if (this->invalid_pw_count >= Config->GetBlock("options")->Get<int>("badpasslimit")) { - this->Kill(Me->GetName(), "Too many invalid passwords"); + this->Kill(Me, "Too many invalid passwords"); return true; } |
