diff options
| author | 2022-12-11 09:58:27 +0000 | |
|---|---|---|
| committer | 2022-12-11 10:14:33 +0000 | |
| commit | 3c6e24665f52e3a38adfe4ab6a9adcbbb4926ca2 (patch) | |
| tree | b2b51956059bd7636aeeb81233aff05983c7687e /src/users.cpp | |
| parent | Improve the oper login flow and error messages. (diff) | |
Move <oper:autologin> from m_sslinfo to core_oper and rework.
- Promote autologin to a core concept with visibility in events.
- Replace the binary yes/no value with strict/relaxed/never. This
intentionally breaks v3 oper block autologin as admins will need
to review them for the security implications of the new behaviour.
Diffstat (limited to 'src/users.cpp')
| -rw-r--r-- | src/users.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/users.cpp b/src/users.cpp index cfa2fe305..0c12dc2fa 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -349,13 +349,13 @@ Cullable::Result FakeUser::Cull() return User::Cull(); } -bool User::OperLogin(const std::shared_ptr<OperAccount>& account, bool force) +bool User::OperLogin(const std::shared_ptr<OperAccount>& account, bool automatic, bool force) { LocalUser* luser = IS_LOCAL(this); if (luser && !quitting && !force) { ModResult modres; - FIRST_MOD_RESULT(OnPreOperLogin, modres, (luser, account)); + FIRST_MOD_RESULT(OnPreOperLogin, modres, (luser, account, automatic)); if (modres == MOD_RES_DENY) return false; // Module rejected the oper attempt. } @@ -364,7 +364,7 @@ bool User::OperLogin(const std::shared_ptr<OperAccount>& account, bool force) if (IsOper()) OperLogout(); - FOREACH_MOD(OnOperLogin, (this, account)); + FOREACH_MOD(OnOperLogin, (this, account, automatic)); // When a user logs in we need to: // 1. Set the operator account (this is what IsOper checks). @@ -385,7 +385,7 @@ bool User::OperLogin(const std::shared_ptr<OperAccount>& account, bool force) } ServerInstance->Users.all_opers.push_back(this); - FOREACH_MOD(OnPostOperLogin, (this)); + FOREACH_MOD(OnPostOperLogin, (this, automatic)); return true; } @@ -1379,6 +1379,12 @@ OperAccount::OperAccount(const std::string& n, const std::shared_ptr<OperType>& , passwordhash(t->getString("hash", "plaintext", 1)) , type(o ? o->GetName() : n) { + autologin = t->getEnum("autologin", AutoLogin::NEVER, { + { "strict", AutoLogin::STRICT }, + { "relaxed", AutoLogin::RELAXED }, + { "never", AutoLogin::NEVER }, + }); + if (o) { chanmodes = o->chanmodes; @@ -1391,6 +1397,24 @@ OperAccount::OperAccount(const std::string& n, const std::shared_ptr<OperType>& Configure(t, true); } +bool OperAccount::CanAutoLogin(LocalUser* user) const +{ + switch (autologin) + { + case AutoLogin::STRICT: + return user->nick == GetName(); + + case AutoLogin::RELAXED: + return true; + + case AutoLogin::NEVER: + return false; + } + + // Should never be reached. + return false; +} + bool OperAccount::CheckPassword(const std::string& pw) const { return ServerInstance->PassCompare(password, pw, passwordhash); |
