From 259b1113944a01aeb450265f03fb97a283e8ef15 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 5 Dec 2015 15:29:01 +0100 Subject: Add rewritten m_cap module - Caps are now managed by m_cap - Each cap uses one bit in an extension item shared with other caps --- src/modules/m_sasl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/modules/m_sasl.cpp') diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index 341b3aea7..297abad85 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -179,8 +179,8 @@ class CommandAuthenticate : public Command { public: SimpleExtItem& authExt; - GenericCap& cap; - CommandAuthenticate(Module* Creator, SimpleExtItem& ext, GenericCap& Cap) + Cap::Capability& cap; + CommandAuthenticate(Module* Creator, SimpleExtItem& ext, Cap::Capability& Cap) : Command(Creator, "AUTHENTICATE", 1), authExt(ext), cap(Cap) { works_before_reg = true; @@ -191,7 +191,7 @@ class CommandAuthenticate : public Command /* Only allow AUTHENTICATE on unregistered clients */ if (user->registered != REG_ALL) { - if (!cap.ext.get(user)) + if (!cap.get(user)) return CMD_FAILURE; SaslAuthenticator *sasl = authExt.get(user); @@ -247,7 +247,7 @@ class CommandSASL : public Command class ModuleSASL : public Module { SimpleExtItem authExt; - GenericCap cap; + Cap::Capability cap; CommandAuthenticate auth; CommandSASL sasl; Events::ModuleEventProvider sasleventprov; -- cgit v1.3.1-10-gc9f91 From 53b9f55c18dd72e8495f84bacfe6683d8df81e66 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 5 Dec 2015 15:39:52 +0100 Subject: m_sasl Create SASLCap which subclasses Cap::Capability and implements OnRequest() --- src/modules/m_sasl.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/modules/m_sasl.cpp') diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index 297abad85..4d1dbbc71 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -24,6 +24,25 @@ #include "modules/sasl.h" #include "modules/ssl.h" +class SASLCap : public Cap::Capability +{ + bool OnRequest(LocalUser* user, bool adding) CXX11_OVERRIDE + { + // Requesting this cap is allowed anytime + if (adding) + return true; + + // But removing it can only be done when unregistered + return (user->registered != REG_ALL); + } + + public: + SASLCap(Module* mod) + : Cap::Capability(mod, "sasl") + { + } +}; + enum SaslState { SASL_INIT, SASL_COMM, SASL_DONE }; enum SaslResult { SASL_OK, SASL_FAIL, SASL_ABORT }; @@ -247,7 +266,7 @@ class CommandSASL : public Command class ModuleSASL : public Module { SimpleExtItem authExt; - Cap::Capability cap; + SASLCap cap; CommandAuthenticate auth; CommandSASL sasl; Events::ModuleEventProvider sasleventprov; @@ -255,7 +274,7 @@ class ModuleSASL : public Module public: ModuleSASL() : authExt("sasl_auth", ExtensionItem::EXT_USER, this) - , cap(this, "sasl") + , cap(this) , auth(this, authExt, cap) , sasl(this, authExt) , sasleventprov(this, "event/sasl") -- cgit v1.3.1-10-gc9f91 From ddc6999a1db1aa1e9bf9df2f1ab444c387bcd5b1 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 5 Dec 2015 16:01:30 +0100 Subject: m_sasl Advertise SASL mechanism list to supporting clients --- src/modules/m_sasl.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/modules/m_sasl.cpp') diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index 4d1dbbc71..7570e7732 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -26,6 +26,8 @@ class SASLCap : public Cap::Capability { + std::string mechlist; + bool OnRequest(LocalUser* user, bool adding) CXX11_OVERRIDE { // Requesting this cap is allowed anytime @@ -36,11 +38,25 @@ class SASLCap : public Cap::Capability return (user->registered != REG_ALL); } + const std::string* GetValue(LocalUser* user) const CXX11_OVERRIDE + { + return &mechlist; + } + public: SASLCap(Module* mod) : Cap::Capability(mod, "sasl") { } + + void SetMechlist(const std::string& newmechlist) + { + if (mechlist == newmechlist) + return; + + mechlist = newmechlist; + NotifyValueChange(); + } }; enum SaslState { SASL_INIT, SASL_COMM, SASL_DONE }; @@ -305,6 +321,12 @@ class ModuleSASL : public Module return MOD_RES_PASSTHRU; } + void OnDecodeMetaData(Extensible* target, const std::string& extname, const std::string& extdata) CXX11_OVERRIDE + { + if ((target == NULL) && (extname == "saslmechlist")) + cap.SetMechlist(extdata); + } + Version GetVersion() CXX11_OVERRIDE { return Version("Provides support for IRC Authentication Layer (aka: SASL) via AUTHENTICATE.", VF_VENDOR); -- cgit v1.3.1-10-gc9f91