From ff93355af851541e21218811eb46190a3eb070a3 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 23 Jun 2014 15:44:06 -0400 Subject: Hold a reference to the type in Serialize::Checker in the event it goes away, and invalidate the type pointer of objects when the type goes away --- src/serialize.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/serialize.cpp b/src/serialize.cpp index 521704df4..570463dc3 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -124,6 +124,15 @@ Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), un Type::~Type() { + /* null the type of existing serializable objects of this type */ + for (std::list::iterator it = Serializable::SerializableItems->begin(); it != Serializable::SerializableItems->end(); ++it) + { + Serializable *s = *it; + + if (s->s_type == this) + s->s_type = NULL; + } + std::vector::iterator it = std::find(TypeOrder.begin(), TypeOrder.end(), this->name); if (it != TypeOrder.end()) TypeOrder.erase(it); -- cgit From d9949320c79fc06a0a370b45d408bc4e0a447704 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 28 Jun 2014 23:13:57 -0400 Subject: Don't try to setuid down until after we signal the parent to exit, unless we're not forking. Also don't issue the run as root warning if we're going to setuid later. --- src/init.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index da91e2fcf..8f479f73e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -100,6 +100,8 @@ bool Anope::AtTerm() return isatty(fileno(stdout)) && isatty(fileno(stdin)) && isatty(fileno(stderr)); } +static void setuidgid(); + void Anope::Fork() { #ifndef _WIN32 @@ -110,6 +112,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("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 @@ -513,7 +522,11 @@ void Anope::Init(int ac, char **av) for (int i = 0; i < Config->CountBlock("module"); ++i) ModuleManager::LoadModule(Config->GetBlock("module", i)->Get("name"), NULL); - setuidgid(); +#ifndef _WIN32 + /* We won't background later, so we should setuid now */ + if (Anope::NoFork || !Anope::AtTerm()) + setuidgid(); +#endif Module *protocol = ModuleManager::FindFirstOf(PROTOCOL); if (protocol == NULL) -- cgit From 07902c03fde41205e5366b852553f1c74c9746dd Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 28 Jun 2014 23:14:48 -0400 Subject: Check that the list of items isn't NULL when destructing types --- src/serialize.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/serialize.cpp b/src/serialize.cpp index 570463dc3..1bb704b41 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -125,13 +125,14 @@ Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), un Type::~Type() { /* null the type of existing serializable objects of this type */ - for (std::list::iterator it = Serializable::SerializableItems->begin(); it != Serializable::SerializableItems->end(); ++it) - { - Serializable *s = *it; - - if (s->s_type == this) - s->s_type = NULL; - } + if (Serializable::SerializableItems != NULL) + for (std::list::iterator it = Serializable::SerializableItems->begin(); it != Serializable::SerializableItems->end(); ++it) + { + Serializable *s = *it; + + if (s->s_type == this) + s->s_type = NULL; + } std::vector::iterator it = std::find(TypeOrder.begin(), TypeOrder.end(), this->name); if (it != TypeOrder.end()) -- cgit From 93cb5d06dbfc716416c312b4fe58eb40e5ae0046 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 11 Jul 2014 01:02:02 -0400 Subject: Fix channelcount with clone --- src/regchannel.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 5c00e291a..37fca0528 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -132,7 +132,7 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), *this = ci; if (this->founder) - --this->founder->channelcount; + ++this->founder->channelcount; this->access->clear(); this->akick->clear(); @@ -200,9 +200,6 @@ ChannelInfo::~ChannelInfo() delete this->memos.GetMemo(i); this->memos.memos->clear(); } - - if (this->founder) - --this->founder->channelcount; } void ChannelInfo::Serialize(Serialize::Data &data) const -- cgit From 3c88f3b8cf7c6536894d7fe74cd2a4c33d246814 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 15 Jul 2014 17:02:14 -0400 Subject: Check modetimes in CheckModes before enabling bouncy modes --- src/channels.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/channels.cpp b/src/channels.cpp index 409cf6b55..d5ed0aa44 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -108,7 +108,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; -- cgit From 24f17de4aaf736264ecdb6a20d51589d20818ad9 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 3 Aug 2014 18:03:07 -0400 Subject: Fix stats u on Windows --- src/messages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/messages.cpp b/src/messages.cpp index d6fd99143..fff379845 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -429,7 +429,7 @@ void Stats::Run(MessageSource &source, const std::vector ¶ms) break; case 'u': { - time_t uptime = Anope::CurTime - Anope::StartTime; + long uptime = static_cast(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]); -- cgit From bf8f62c32d6c66e38c167e6ca0ac59d29db52326 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 24 Aug 2014 16:39:04 -0400 Subject: Change Channel::GetModeList to return a copy of the mode list, not a pair of lower/upper bound iterators. Sometimes when iterating the list, like in cs_mode, we can modify the contents of it, which combined with mlock always agressively trying to readd modes to it can do bad things. --- src/channels.cpp | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/channels.cpp b/src/channels.cpp index d5ed0aa44..0ef8cf532 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -202,9 +202,9 @@ size_t Channel::HasMode(const Anope::string &mname, const Anope::string ¶m) { if (param.empty()) return modes.count(mname); - std::pair its = this->GetModeList(mname); - for (; its.first != its.second; ++its.first) - if (its.first->second.equals_ci(param)) + std::vector v = this->GetModeList(mname); + for (unsigned int i = 0; i < v.size(); ++i) + if (v[i].equals_ci(param)) return 1; return 0; } @@ -240,12 +240,20 @@ const Channel::ModeList &Channel::GetModes() const return this->modes; } -std::pair Channel::GetModeList(const Anope::string &mname) +template +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 &p) + { + return p.second; + } +}; + +std::vector Channel::GetModeList(const Anope::string &mname) +{ + std::vector r; + std::transform(modes.lower_bound(mname), modes.upper_bound(mname), std::back_inserter(r), second()); + return r; } void Channel::SetModeInternal(MessageSource &setter, ChannelMode *ocm, const Anope::string &oparam, bool enforce_mlock) @@ -363,11 +371,10 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *ocm, const if (cm->type == MODE_LIST) { - std::pair 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; } } @@ -715,11 +722,10 @@ bool Channel::MatchesList(User *u, const Anope::string &mode) if (!this->HasMode(mode)) return false; - - std::pair m = this->GetModeList(mode); - for (; m.first != m.second; ++m.first) + std::vector 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; } @@ -872,11 +878,10 @@ bool Channel::Unban(User *u, const Anope::string &mode, bool full) bool ret = false; - std::pair bans = this->GetModeList(mode); - for (; bans.first != bans.second;) + std::vector 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()); -- cgit From 5ceee5df3854e71ce1c8da409fe50a705efae8ad Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 12 Oct 2014 14:32:17 -0400 Subject: Hide dumb user notice if we are quitting --- src/uplink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/uplink.cpp b/src/uplink.cpp index 8f54794a2..86851fc50 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -66,7 +66,7 @@ UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[Anope::CurrentUplink]. UplinkSocket::~UplinkSocket() { - if (!error) + if (!error && !Anope::Quitting) { this->OnError(""); Module *protocol = ModuleManager::FindFirstOf(PROTOCOL); -- cgit From 48be41cf7b9e8e3390114236be0c099149060791 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 12 Oct 2014 14:34:15 -0400 Subject: Squit uplink when I receive an squit for myself --- src/messages.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/messages.cpp b/src/messages.cpp index fff379845..1c48c6288 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -389,6 +389,14 @@ void SQuit::Run(MessageSource &source, const std::vector ¶ms) return; } + if (s == Me) + { + if (Me->GetLinks().empty()) + return; + + s = Me->GetLinks().front(); + } + s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); } -- cgit From 0cd3bfa24fccea79a5055bcd12d6aa607ecc635e Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 14 Oct 2014 18:58:55 -0400 Subject: Fix module event prioritization which was broken with the newer auto-attach event stuff. Also remove logically dead code from os_defcon, and make os_defcon akill similar masks to os_session when enforcing session akills. Fixes #1618 which relies on os_session to be prioritized before os_defcon. --- src/module.cpp | 4 ++++ src/modulemanager.cpp | 2 ++ 2 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/module.cpp b/src/module.cpp index d57538e59..96fa24f6f 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -101,6 +101,10 @@ void Module::SetAuthor(const Anope::string &nauthor) this->author = nauthor; } +void Module::Prioritize() +{ +} + ModuleVersion::ModuleVersion(int maj, int min, int pa) : version_major(maj), version_minor(min), version_patch(pa) { } diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 71e692dd2..2e7c624cd 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -265,6 +265,8 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) for (unsigned i = 0; i < I_SIZE; ++i) EventHandlers[i].push_back(m); + m->Prioritize(); + FOREACH_MOD(OnModuleLoad, (u, m)); return MOD_ERR_OK; -- cgit From 4f76bee2735f221fa80bbb309ac5e732f723478d Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 24 Nov 2014 21:59:55 -0500 Subject: Fix sid generator generating invalid sids after sid 999 --- src/protocol.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/protocol.cpp b/src/protocol.cpp index 692ce005a..05bcb54fe 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); -- cgit From afffeb0a1d49c1ac8f06ac9850929a41a52cbc7e Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 5 Dec 2014 17:27:08 -0500 Subject: Update Kill() calls to pass source pointer instead of name --- src/messages.cpp | 2 +- src/users.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/messages.cpp b/src/messages.cpp index 1c48c6288..d40b11188 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -203,7 +203,7 @@ void Kill::Run(MessageSource &source, const std::vector ¶ms) bi->OnKill(); } else - u->KillInternal(source.GetSource(), params[1]); + u->KillInternal(source, params[1]); } void Message::Mode::Run(MessageSource &source, const std::vector ¶ms) diff --git a/src/users.cpp b/src/users.cpp index 2a04fca20..8ec13d8c0 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -805,7 +805,7 @@ bool User::BadPassword() this->invalid_pw_time = Anope::CurTime; if (this->invalid_pw_count >= Config->GetBlock("options")->Get("badpasslimit")) { - this->Kill(Me->GetName(), "Too many invalid passwords"); + this->Kill(Me, "Too many invalid passwords"); return true; } -- cgit From e1f5e030bc8edac10da922e0402744b1e2f023c8 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 5 Dec 2014 20:24:27 -0500 Subject: Change webpanel access add to just add via the commands, split Command::Run into two so I can do this as I need to run named commands for it --- src/command.cpp | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/command.cpp b/src/command.cpp index 6aa2f744b..2786edecf 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -236,18 +236,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(NICK_IDENTIFY_REQUIRED); - 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()); @@ -257,17 +245,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 ¶ms) +{ + if (this->RequireUser() && !source.GetUser()) + return; + + // Command requires registered users only + if (!this->AllowUnregistered() && !source.nc) + { + source.Reply(NICK_IDENTIFY_REQUIRED); + 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; - FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, c, params)); + FOREACH_RESULT(OnPreCommand, MOD_RESULT, (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; } @@ -276,12 +281,12 @@ void Command::Run(CommandSource &source, const Anope::string &message) { source.Reply(ACCESS_DENIED); 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); - FOREACH_MOD(OnPostCommand, (source, c, params)); + this->Execute(source, params); + FOREACH_MOD(OnPostCommand, (source, this, params)); } bool Command::FindCommandFromService(const Anope::string &command_service, BotInfo* &bot, Anope::string &name) -- cgit From e4068249dd2ba4f198c7ef0117743896248769a4 Mon Sep 17 00:00:00 2001 From: MichaƂ Zegan Date: Fri, 12 Dec 2014 19:46:20 +0100 Subject: Anope will now fork even when not started from a tty, like init scrpits. It is useful for init systems or startup scripts, because it allows easily waiting until services connect to the uplink, without them forking it wouldn't be possible to tell if they finished initialization or not unless they would communicate directly with init systems like systemd. --- src/init.cpp | 4 ++-- src/servers.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index 8f479f73e..e6bc8e150 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -440,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 @@ -524,7 +524,7 @@ void Anope::Init(int ac, char **av) #ifndef _WIN32 /* We won't background later, so we should setuid now */ - if (Anope::NoFork || !Anope::AtTerm()) + if (Anope::NoFork) setuidgid(); #endif diff --git a/src/servers.cpp b/src/servers.cpp index 3427c2beb..6401d8d59 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -287,7 +287,7 @@ void Server::Sync(bool sync_links) FOREACH_MOD(OnUplinkSync, (this)); - if (!Anope::NoFork && Anope::AtTerm()) + if (!Anope::NoFork) { Log(LOG_TERMINAL) << "Successfully linked, launching into background..."; Anope::Fork(); -- cgit From 2892c9580faed747adb5b5f775f2878170713f52 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 28 Dec 2014 18:09:37 -0500 Subject: Replace spaces in opertypes with underscores in stats o --- src/messages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/messages.cpp b/src/messages.cpp index d40b11188..7036acfc7 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -428,7 +428,7 @@ void Stats::Run(MessageSource &source, const std::vector ¶ms) const NickAlias *na = NickAlias::Find(o->name); if (na) - IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str()); + IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().replace_all_cs(" ", "_").c_str()); } IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); -- cgit