1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 /* $ModDesc: Provides support for atheme SASL via AUTHENTICATE. */
20 class CommandAuthenticate : public Command
24 CommandAuthenticate (InspIRCd* Instance, Module* creator) : Command(Instance,"AUTHENTICATE", 0, 1, true), Creator(creator)
26 this->source = "m_sasl.so";
29 CmdResult Handle (const char* const* parameters, int pcnt, User *user)
31 if (user->registered != REG_ALL)
33 /* Only act if theyve enabled CAP REQ sasl */
34 if (user->GetExt("sasl"))
36 /* Only allow AUTHENTICATE on unregistered clients */
37 std::deque<std::string> params;
38 params.push_back("*");
39 params.push_back("AUTHENTICATE");
40 params.push_back(user->uuid);
42 for (int i = 0; i < pcnt; ++i)
43 params.push_back(parameters[i]);
45 Event e((char*)¶ms, Creator, "send_encap");
46 e.Send(ServerInstance);
54 class ModuleSASL : public Module
56 CommandAuthenticate* sasl;
59 ModuleSASL(InspIRCd* Me)
62 Implementation eventlist[] = { I_OnEvent, I_OnUserRegister };
63 ServerInstance->Modules->Attach(eventlist, this, 2);
65 sasl = new CommandAuthenticate(ServerInstance, this);
66 ServerInstance->AddCommand(sasl);
68 if (!ServerInstance->Modules->Find("m_services_account.so") || !ServerInstance->Modules->Find("m_cap.so"))
69 ServerInstance->Logs->Log("m_sasl", DEFAULT, "WARNING: m_services_account.so and m_cap.so are not loaded! m_sasl.so will NOT function correctly until these two modules are loaded!");
72 virtual int OnUserRegister(User *user)
74 std::string* str = NULL;
76 if (user->GetExt("sasl"))
78 user->WriteServ("906 %s :SASL authentication aborted", user->nick);
82 if (user->GetExt("acountname", str))
84 std::deque<std::string> params;
85 params.push_back(user->uuid);
86 params.push_back("accountname");
87 params.push_back(*str);
88 Event e((char*)¶ms, this, "send_metadata");
89 e.Send(ServerInstance);
98 virtual Version GetVersion()
100 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
103 virtual void OnEvent(Event *ev)
105 GenericCapHandler(ev, "sasl", "sasl");
107 if (ev->GetEventID() == "encap_received")
109 /* Received encap reply, look for AUTHENTICATE */
110 std::deque<std::string>* parameters = (std::deque<std::string>*)ev->GetData();
112 User* target = ServerInstance->FindNick((*parameters)[0]);
117 parameters->pop_front();
118 std::string line = irc::stringjoiner(" ", *parameters, 0, parameters->size() - 1).GetJoined();
119 target->WriteServ("AUTHENTICATE %s", line.c_str());
122 else if (ev->GetEventID() == "account_login")
124 AccountData* ac = (AccountData*)ev->GetData();
126 if (ac->user->GetExt("sasl"))
128 ac->user->WriteServ("903 %s :SASL authentication successful", ac->user->nick);
129 ac->user->Shrink("sasl");
135 MODULE_INIT(ModuleSASL)