diff options
| author | 2022-05-14 14:35:07 +0100 | |
|---|---|---|
| committer | 2022-05-14 14:47:56 +0100 | |
| commit | 986d587ea4bba1e89fc241220621d0834464ea28 (patch) | |
| tree | 3783ead7019d3c85d9a3a241887442c05cf56de9 /src/modules | |
| parent | Remove the old account system. (diff) | |
Add the new account system.
This still relies on the old extensibles for now but we can change
that later.
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/m_filter.cpp | 7 | ||||
| -rw-r--r-- | src/modules/m_hostchange.cpp | 5 | ||||
| -rw-r--r-- | src/modules/m_ircv3.cpp | 12 | ||||
| -rw-r--r-- | src/modules/m_ircv3_accounttag.cpp | 19 | ||||
| -rw-r--r-- | src/modules/m_passforward.cpp | 6 | ||||
| -rw-r--r-- | src/modules/m_restrictchans.cpp | 5 | ||||
| -rw-r--r-- | src/modules/m_securelist.cpp | 5 | ||||
| -rw-r--r-- | src/modules/m_services_account.cpp | 69 |
8 files changed, 81 insertions, 47 deletions
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index ba8845cfe..cfb623557 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -194,8 +194,10 @@ class ModuleFilter final , public Stats::EventListener , public Timer { +private: typedef insp::flat_set<std::string, irc::insensitive_swo> ExemptTargetSet; + Account::API accountapi; bool initing = true; bool notifyuser; bool warnonselfmsg; @@ -336,11 +338,9 @@ CmdResult CommandFilter::Handle(User* user, const Params& parameters) bool ModuleFilter::AppliesToMe(User* user, const FilterResult& filter, int iflags) { - const AccountExtItem* accountext = GetAccountExtItem(); - if ((filter.flag_no_opers) && user->IsOper()) return false; - if ((filter.flag_no_registered) && accountext && accountext->Get(user)) + if ((filter.flag_no_registered) && accountapi && accountapi->GetAccountName(user)) return false; if ((iflags & FLAG_PRIVMSG) && (!filter.flag_privmsg)) return false; @@ -358,6 +358,7 @@ ModuleFilter::ModuleFilter() , ServerProtocol::SyncEventListener(this) , Stats::EventListener(this) , Timer(0, true) + , accountapi(this) , filtcommand(this) , RegexEngine(this) { diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 5fe705766..00a665b17 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -126,6 +126,7 @@ class ModuleHostChange final : public Module { private: + Account::API accountapi; std::bitset<UCHAR_MAX + 1> hostmap; HostRules hostrules; @@ -144,6 +145,7 @@ private: public: ModuleHostChange() : Module(VF_VENDOR, "Allows the server administrator to define custom rules for applying hostnames to users.") + , accountapi(this) { } @@ -207,8 +209,7 @@ public: if (rule.GetAction() == HostRule::HCA_ADDACCOUNT) { // Retrieve the account name. - const AccountExtItem* accountext = GetAccountExtItem(); - const std::string* accountptr = accountext ? accountext->Get(user) : NULL; + const std::string* accountptr = accountapi ? accountapi->GetAccountName(user) : nullptr; if (!accountptr) continue; diff --git a/src/modules/m_ircv3.cpp b/src/modules/m_ircv3.cpp index beefa24a4..ea3c157a6 100644 --- a/src/modules/m_ircv3.cpp +++ b/src/modules/m_ircv3.cpp @@ -51,6 +51,8 @@ public: class JoinHook final : public ClientProtocol::EventHook { +private: + Account::API accountapi; ClientProtocol::Events::Join extendedjoinmsg; public: @@ -62,6 +64,7 @@ public: JoinHook(Module* mod) : ClientProtocol::EventHook(mod, "JOIN") + , accountapi(mod) , asterisk(1, '*') , awayprotoev(mod, "AWAY") , extendedjoincap(mod, "extended-join") @@ -79,10 +82,9 @@ public: Membership* const memb = join.GetMember(); const std::string* account = &asterisk; - const AccountExtItem* const accountext = GetAccountExtItem(); - if (accountext) + if (accountapi) { - const std::string* accountname = accountext->Get(memb->user); + const std::string* accountname = accountapi->GetAccountName(memb->user); if (accountname) account = accountname; } @@ -115,7 +117,7 @@ public: class ModuleIRCv3 final : public Module - , public AccountEventListener + , public Account::EventListener , public Away::EventListener { private: @@ -126,7 +128,7 @@ private: public: ModuleIRCv3() : Module(VF_VENDOR, "Provides the IRCv3 account-notify, away-notify, and extended-join client capabilities.") - , AccountEventListener(this) + , Account::EventListener(this) , Away::EventListener(this) , cap_accountnotify(this, "account-notify") , joinhook(this) diff --git a/src/modules/m_ircv3_accounttag.cpp b/src/modules/m_ircv3_accounttag.cpp index 20044ebf8..52dc64fda 100644 --- a/src/modules/m_ircv3_accounttag.cpp +++ b/src/modules/m_ircv3_accounttag.cpp @@ -26,22 +26,22 @@ class AccountTag final : public IRCv3::CapTag<AccountTag> { +private: + Account::API accountapi; + public: const std::string* GetValue(const ClientProtocol::Message& msg) const { User* const user = msg.GetSourceUser(); - if (!user) - return NULL; - - AccountExtItem* const accextitem = GetAccountExtItem(); - if (!accextitem) - return NULL; + if (!user || !accountapi) + return nullptr; - return accextitem->Get(user); + return accountapi->GetAccountName(user); } AccountTag(Module* mod) : IRCv3::CapTag<AccountTag>(mod, "account-tag", "account") + , accountapi(mod) { } }; @@ -50,12 +50,14 @@ class AccountIdTag final : public ClientProtocol::MessageTagProvider { private: + Account::API accountapi; AccountTag& acctag; CTCTags::CapReference ctctagcap; public: AccountIdTag(Module* mod, AccountTag& tag) : ClientProtocol::MessageTagProvider(mod) + , accountapi(mod) , acctag(tag) , ctctagcap(mod) { @@ -64,8 +66,7 @@ public: void OnPopulateTags(ClientProtocol::Message& msg) override { const User* user = msg.GetSourceUser(); - const AccountExtItem* accextitem = user ? GetAccountIdExtItem() : nullptr; - const std::string* accountid = accextitem ? accextitem->Get(user) : nullptr; + const std::string* accountid = accountapi ? accountapi->GetAccountId(user) : nullptr; if (accountid) msg.AddTag("inspircd.org/account-id", this, *accountid); } diff --git a/src/modules/m_passforward.cpp b/src/modules/m_passforward.cpp index 76cdbf64c..f9046032c 100644 --- a/src/modules/m_passforward.cpp +++ b/src/modules/m_passforward.cpp @@ -29,11 +29,14 @@ class ModulePassForward final : public Module { +private: + Account::API accountapi; std::string nickrequired, forwardmsg, forwardcmd; public: ModulePassForward() : Module(VF_VENDOR, "Allows an account password to be forwarded to a services pseudoclient such as NickServ.") + , accountapi(this) { } @@ -90,8 +93,7 @@ public: if (!user->GetClass()->config->getString("password").empty()) return; - AccountExtItem* actext = GetAccountExtItem(); - if (actext && actext->Get(user)) + if (accountapi && accountapi->GetAccountName(user)) { // User is logged in already (probably via SASL) don't forward the password return; diff --git a/src/modules/m_restrictchans.cpp b/src/modules/m_restrictchans.cpp index 661e7fd28..3132083d1 100644 --- a/src/modules/m_restrictchans.cpp +++ b/src/modules/m_restrictchans.cpp @@ -32,13 +32,13 @@ class ModuleRestrictChans final : public Module { private: + Account::API accountapi; AllowChans allowchans; bool allowregistered = false; bool CanCreateChannel(LocalUser* user, const std::string& name) { - const AccountExtItem* accountext = GetAccountExtItem(); - if (allowregistered && accountext && accountext->Get(user)) + if (allowregistered && accountapi && accountapi->GetAccountName(user)) return true; if (user->HasPrivPermission("channels/restricted-create")) @@ -56,6 +56,7 @@ private: public: ModuleRestrictChans() : Module(VF_VENDOR, "Prevents unprivileged users from creating new channels.") + , accountapi(this) { } diff --git a/src/modules/m_securelist.cpp b/src/modules/m_securelist.cpp index cbab8835e..98e995a8f 100644 --- a/src/modules/m_securelist.cpp +++ b/src/modules/m_securelist.cpp @@ -35,6 +35,7 @@ class ModuleSecureList final , public ISupport::EventListener { private: + Account::API accountapi; AllowList allowlist; bool exemptregistered; unsigned long fakechans; @@ -47,6 +48,7 @@ public: ModuleSecureList() : Module(VF_VENDOR, "Prevents users from using the /LIST command until a predefined period has passed.") , ISupport::EventListener(this) + , accountapi(this) { } @@ -95,8 +97,7 @@ public: } // Allow if the source is logged in and <securelist:exemptregistered> is set. - const AccountExtItem* ext = GetAccountExtItem(); - if (exemptregistered && ext && ext->Get(user)) + if (exemptregistered && accountapi && accountapi->GetAccountName(user)) return MOD_RES_PASSTHRU; // If <securehost:showmsg> is set then tell the user that they need to wait. diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp index 2e2334c24..12939718f 100644 --- a/src/modules/m_services_account.cpp +++ b/src/modules/m_services_account.cpp @@ -93,13 +93,13 @@ public: }; class AccountExtItemImpl final - : public AccountExtItem + : public StringExtItem { Events::ModuleEventProvider eventprov; public: AccountExtItemImpl(Module* mod) - : AccountExtItem(mod, "accountname", ExtensionType::USER, true) + : StringExtItem(mod, "accountname", ExtensionType::USER, true) , eventprov(mod, "event/account") { } @@ -126,7 +126,33 @@ public: } } - eventprov.Call(&AccountEventListener::OnAccountChange, user, value); + eventprov.Call(&Account::EventListener::OnAccountChange, user, value); + } +}; + +class AccountAPIImpl final + : public Account::APIBase +{ +private: + AccountExtItemImpl accountext; + StringExtItem accountidext; + +public: + AccountAPIImpl(Module* mod) + : Account::APIBase(mod) + , accountext(mod) + , accountidext(mod, "accountid", ExtensionType::USER, true) + { + } + + std::string* GetAccountId(const User* user) const override + { + return accountidext.Get(user); + } + + std::string* GetAccountName(const User* user) const override + { + return accountext.Get(user); } }; @@ -134,18 +160,18 @@ class AccountExtBan final : public ExtBan::MatchingBase { private: - AccountExtItemImpl& accountext; + AccountAPIImpl& accountapi; public: - AccountExtBan(Module* Creator, AccountExtItemImpl& AccountExt) + AccountExtBan(Module* Creator, AccountAPIImpl& AccountAPI) : ExtBan::MatchingBase(Creator, "account", 'R') - , accountext(AccountExt) + , accountapi(AccountAPI) { } bool IsMatch(User* user, Channel* channel, const std::string& text) override { - const std::string* account = accountext.Get(user); + const std::string* account = accountapi.GetAccountName(user); return account && InspIRCd::Match(*account, text); } }; @@ -154,18 +180,18 @@ class UnauthedExtBan final : public ExtBan::MatchingBase { private: - AccountExtItemImpl& accountext; + AccountAPIImpl& accountapi; public: - UnauthedExtBan(Module* Creator, AccountExtItemImpl& AccountExt) + UnauthedExtBan(Module* Creator, AccountAPIImpl& AccountAPI) : ExtBan::MatchingBase(Creator, "unauthed", 'U') - , accountext(AccountExt) + , accountapi(AccountAPI) { } bool IsMatch(User* user, Channel* channel, const std::string& text) override { - const std::string* account = accountext.Get(user); + const std::string* account = accountapi.GetAccountName(user); return !account && channel->CheckBan(user, text); } }; @@ -184,8 +210,7 @@ private: SimpleUserMode regdeafmode; RegisteredChannel chanregmode; RegisteredUser userregmode; - AccountExtItem accountid; - AccountExtItemImpl accountname; + AccountAPIImpl accountapi; AccountExtBan accountextban; UnauthedExtBan unauthedextban; @@ -202,10 +227,9 @@ public: , regdeafmode(this, "regdeaf", 'R') , chanregmode(this) , userregmode(this) - , accountid(this, "accountid", ExtensionType::USER, true) - , accountname(this) - , accountextban(this, accountname) - , unauthedextban(this, accountname) + , accountapi(this) + , accountextban(this, accountapi) + , unauthedextban(this, accountapi) { } @@ -225,8 +249,7 @@ public: /* <- :twisted.oscnet.org 330 w00t2 w00t2 w00t :is logged in as */ void OnWhois(Whois::Context& whois) override { - std::string* account = accountname.Get(whois.GetTarget()); - + const std::string* account = accountapi.GetAccountName(whois.GetTarget()); if (account) { whois.SendLine(RPL_WHOISACCOUNT, *account, "is logged in as"); @@ -251,7 +274,8 @@ public: if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; - std::string *account = accountname.Get(user); + + const std::string* account = accountapi.GetAccountName(user); bool is_registered = account && !account->empty(); switch (target.type) @@ -304,7 +328,8 @@ public: if (override) return MOD_RES_PASSTHRU; - std::string *account = accountname.Get(user); + + const std::string* account = accountapi.GetAccountName(user); bool is_registered = account && !account->empty(); if (chan) @@ -324,7 +349,7 @@ public: ModResult OnSetConnectClass(LocalUser* user, ConnectClass::Ptr myclass) override { - if (myclass->config->getBool("requireaccount") && !accountname.Get(user)) + if (myclass->config->getBool("requireaccount") && !accountapi.GetAccountName(user)) { ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires the user to be logged into an account", myclass->GetName().c_str()); |
