diff options
author | Adam <Adam@anope.org> | 2016-11-11 12:58:14 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-11-11 12:58:14 -0500 |
commit | ef5b6919e3508cc9d4c722285d9d56f5a275f650 (patch) | |
tree | 56497f0a4f5d1847bae511c72bdb2d3581df58ef /src | |
parent | 8dd6e3195ed7600e39935e887df2626215733dfb (diff) |
Fix opers not really being serializable
Diffstat (limited to 'src')
-rw-r--r-- | src/command.cpp | 16 | ||||
-rw-r--r-- | src/config.cpp | 54 | ||||
-rw-r--r-- | src/opertype.cpp | 16 | ||||
-rw-r--r-- | src/users.cpp | 46 |
4 files changed, 76 insertions, 56 deletions
diff --git a/src/command.cpp b/src/command.cpp index ade17fd45..f1cae4bb3 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -74,8 +74,10 @@ bool CommandSource::HasCommand(const Anope::string &cmd) { if (this->u) return this->u->HasCommand(cmd); - else if (this->nc && this->nc->o) - return this->nc->o->GetType()->HasCommand(cmd); + + if (this->nc && this->nc->GetOper()) + return this->nc->GetOper()->HasCommand(cmd); + return false; } @@ -83,8 +85,10 @@ bool CommandSource::HasPriv(const Anope::string &cmd) { if (this->u) return this->u->HasPriv(cmd); - else if (this->nc && this->nc->o) - return this->nc->o->GetType()->HasPriv(cmd); + + if (this->nc && this->nc->GetOper()) + return this->nc->GetOper()->HasPriv(cmd); + return false; } @@ -93,7 +97,7 @@ bool CommandSource::IsServicesOper() if (this->u) return this->u->IsServicesOper(); else if (this->nc) - return this->nc->IsServicesOper(); + return this->nc->GetOper() != nullptr; return false; } @@ -102,7 +106,7 @@ bool CommandSource::IsOper() if (this->u) return this->u->HasMode("OPER"); else if (this->nc) - return this->nc->IsServicesOper(); + return this->nc->GetOper() != nullptr; return false; } diff --git a/src/config.cpp b/src/config.cpp index e8f81c1a2..e34177e8f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -511,18 +511,19 @@ Conf::Conf() : Block("") /* Clear existing conf opers */ if (Config) - for (Oper *o : Serialize::GetObjects<Oper *>()) - if (o->conf == Config) - o->Delete(); - /* Apply new opers */ - for (Oper *o : Serialize::GetObjects<Oper *>()) { - NickServ::Nick *na = NickServ::FindNick(o->GetName()); - if (!na) - continue; + for (int i = 0; i < Config->CountBlock("oper"); ++i) + { + Block *oper = Config->GetBlock("oper", i); - na->GetAccount()->o = o; - Log() << "Tied oper " << na->GetAccount()->GetDisplay() << " to type " << o->GetType()->GetName(); + const Anope::string &nname = oper->Get<Anope::string>("name"); + + Oper *o = Oper::Find(nname); + if (o != nullptr) + { + o->Delete(); + } + } } /* Check the user keys */ @@ -575,27 +576,6 @@ void Conf::Post(Conf *old) ModeManager::Apply(old); - /* Apply opertype changes, as non-conf opers still point to the old oper types */ - for (Oper *o : Serialize::GetObjects<Oper *>()) - { - /* Oper's type is in the old config, so update it */ - if (std::find(old->MyOperTypes.begin(), old->MyOperTypes.end(), o->GetType()) != old->MyOperTypes.end()) - { - OperType *ot = o->GetType(); - o->SetType(nullptr); - - for (unsigned j = 0; j < MyOperTypes.size(); ++j) - if (ot->GetName() == MyOperTypes[j]->GetName()) - o->SetType(MyOperTypes[j]); - - if (o->GetType() == NULL) - { - /* Oper block has lost type */ - o->Delete(); - } - } - } - for (BotInfo *bi : Serialize::GetObjects<BotInfo *>()) { if (!bi->conf) @@ -753,7 +733,6 @@ void Conf::LoadOpers() if (o == nullptr) o = Serialize::New<Oper *>(); - o->conf = this; o->SetName(nname); o->SetType(ot); o->SetRequireOper(require_oper); @@ -764,6 +743,17 @@ void Conf::LoadOpers() Log(LOG_DEBUG) << "Creating oper " << nname << " of type " << ot->GetName(); } + + /* Apply new opers */ + for (Oper *o : Serialize::GetObjects<Oper *>()) + { + NickServ::Nick *na = NickServ::FindNick(o->GetName()); + if (!na) + continue; + + na->GetAccount()->SetOper(o); + Log() << "Tied oper " << na->GetAccount()->GetDisplay() << " to type " << o->GetType()->GetName(); + } } Block *Conf::GetModule(Module *m) diff --git a/src/opertype.cpp b/src/opertype.cpp index 91676bd84..c9c1b762c 100644 --- a/src/opertype.cpp +++ b/src/opertype.cpp @@ -93,6 +93,22 @@ void Oper::SetRequireOper(const bool &b) Set(&OperBlockType::require_oper, b); } +bool Oper::HasCommand(const Anope::string &cmdstr) +{ + OperType *type = GetType(); + if (type != nullptr) + return type->HasCommand(cmdstr); + return false; +} + +bool Oper::HasPriv(const Anope::string &cmdstr) +{ + OperType *type = GetType(); + if (type != nullptr) + return type->HasPriv(cmdstr); + return false; +} + Oper *Oper::Find(const Anope::string &name) { for (Oper *o : Serialize::GetObjects<Oper *>()) diff --git a/src/users.cpp b/src/users.cpp index 3c081a918..12f61a889 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -389,9 +389,10 @@ void User::Identify(NickServ::Nick *na) EventManager::Get()->Dispatch(&Event::NickIdentify::OnNickIdentify, this); - if (this->IsServicesOper()) + Oper *oper = this->nc->GetOper(); + if (oper != nullptr && oper->GetType() != nullptr) { - Anope::string m = this->nc->o->GetType()->modes; + Anope::string m = oper->GetType()->modes; if (!m.empty()) { this->SetModes(NULL, "%s", m.c_str()); @@ -400,11 +401,11 @@ void User::Identify(NickServ::Nick *na) if (um && !this->HasMode("OPER") && m.find(um->mchar) != Anope::string::npos) IRCD->SendOper(this); } - if (IRCD->CanSetVHost && !this->nc->o->GetVhost().empty()) + if (IRCD->CanSetVHost && !oper->GetVhost().empty()) { - this->SendMessage(Me, "Changing your vhost to \002{0}\002", this->nc->o->GetVhost()); - this->SetDisplayedHost(this->nc->o->GetVhost()); - IRCD->SendVhost(this, "", this->nc->o->GetVhost()); + this->SendMessage(Me, "Changing your vhost to \002{0}\002", oper->GetVhost()); + this->SetDisplayedHost(oper->GetVhost()); + IRCD->SendVhost(this, "", oper->GetVhost()); } } } @@ -472,18 +473,26 @@ bool User::IsRecognized(bool check_secure) const bool User::IsServicesOper() { - if (!this->nc || !this->nc->IsServicesOper()) + if (!this->nc || !this->nc->GetOper()) // No opertype. return false; - else if (this->nc->o->GetRequireOper() && !this->HasMode("OPER")) + + Oper *oper = this->nc->GetOper(); + + if (oper->GetType() == nullptr) return false; - else if (!this->nc->o->GetCertFP().empty() && this->fingerprint != this->nc->o->GetCertFP()) + + if (oper->GetRequireOper() && !this->HasMode("OPER")) + return false; + + if (!oper->GetCertFP().empty() && this->fingerprint != oper->GetCertFP()) // Certfp mismatch return false; - else if (!this->nc->o->GetHost().empty()) + + if (!oper->GetHost().empty()) { std::vector<Anope::string> hosts; - spacesepstream(this->nc->o->GetHost()).GetTokens(hosts); + spacesepstream(oper->GetHost()).GetTokens(hosts); bool match = false; Anope::string match_host = this->GetIdent() + "@" + this->host; @@ -505,14 +514,14 @@ bool User::IsServicesOper() bool User::HasCommand(const Anope::string &command) { if (this->IsServicesOper()) - return this->nc->o->GetType()->HasCommand(command); + return this->nc->GetOper()->HasCommand(command); return false; } bool User::HasPriv(const Anope::string &priv) { if (this->IsServicesOper()) - return this->nc->o->GetType()->HasPriv(priv); + return this->nc->GetOper()->HasPriv(priv); return false; } @@ -556,7 +565,8 @@ void User::SetModeInternal(const MessageSource &source, UserMode *um, const Anop if (this->IsServicesOper()) { - Anope::string m = this->nc->o->GetType()->modes; + Oper *oper = this->nc->GetOper(); + Anope::string m = oper->GetType()->modes; if (!m.empty()) { this->SetModes(NULL, "%s", m.c_str()); @@ -565,11 +575,11 @@ void User::SetModeInternal(const MessageSource &source, UserMode *um, const Anop if (oper && !this->HasMode("OPER") && m.find(oper->mchar) != Anope::string::npos) IRCD->SendOper(this); } - if (IRCD->CanSetVHost && !this->nc->o->GetVhost().empty()) + if (IRCD->CanSetVHost && !oper->GetVhost().empty()) { - this->SendMessage(Me, "Changing your vhost to \002{0}\002", this->nc->o->GetVhost()); - this->SetDisplayedHost(this->nc->o->GetVhost()); - IRCD->SendVhost(this, "", this->nc->o->GetVhost()); + this->SendMessage(Me, "Changing your vhost to \002{0}\002", oper->GetVhost()); + this->SetDisplayedHost(oper->GetVhost()); + IRCD->SendVhost(this, "", oper->GetVhost()); } } } |