]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sasl.cpp
Merge pull request #1168 from SaberUK/master+fix-configure-cache-parser
[user/henk/code/inspircd.git] / src / modules / m_sasl.cpp
index 4d1dbbc71df04f0b8d9aa7e44f9186d2596a944e..639fe677863ece5a76dd5c39448393298cce6813 100644 (file)
@@ -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 };
@@ -126,7 +142,7 @@ class SaslAuthenticator
                                this->result = this->GetSaslResult(msg[3]);
                        }
                        else if (msg[2] == "M")
-                               this->user->WriteNumeric(908, "%s %s :are available SASL mechanisms", this->user->nick.c_str(), msg[3].c_str());
+                               this->user->WriteNumeric(908, msg[3], "are available SASL mechanisms");
                        else
                                ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Services sent an unknown SASL message \"%s\" \"%s\"", msg[2].c_str(), msg[3].c_str());
 
@@ -178,13 +194,13 @@ class SaslAuthenticator
                switch (this->result)
                {
                 case SASL_OK:
-                       this->user->WriteNumeric(903, ":SASL authentication successful");
+                       this->user->WriteNumeric(903, "SASL authentication successful");
                        break;
                 case SASL_ABORT:
-                       this->user->WriteNumeric(906, ":SASL authentication aborted");
+                       this->user->WriteNumeric(906, "SASL authentication aborted");
                        break;
                 case SASL_FAIL:
-                       this->user->WriteNumeric(904, ":SASL authentication failed");
+                       this->user->WriteNumeric(904, "SASL authentication failed");
                        break;
                 default:
                        break;
@@ -207,8 +223,6 @@ class CommandAuthenticate : public Command
 
        CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
-               /* Only allow AUTHENTICATE on unregistered clients */
-               if (user->registered != REG_ALL)
                {
                        if (!cap.get(user))
                                return CMD_FAILURE;
@@ -237,8 +251,8 @@ class CommandSASL : public Command
 
        CmdResult Handle(const std::vector<std::string>& parameters, User *user)
        {
-               User* target = ServerInstance->FindNick(parameters[1]);
-               if ((!target) || (IS_SERVER(target)))
+               User* target = ServerInstance->FindUUID(parameters[1]);
+               if (!target)
                {
                        ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "User not found in sasl ENCAP event: %s", parameters[1].c_str());
                        return CMD_FAILURE;
@@ -305,6 +319,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);