]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sasl.cpp
Add capability for m_services_account to broadcast login events, with the user who...
[user/henk/code/inspircd.git] / src / modules / m_sasl.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "m_cap.h"
16 #include "account.h"
17
18 /* $ModDesc: Provides support for atheme SASL via AUTHENTICATE. */
19
20 class CommandAuthenticate : public Command
21 {
22  public:
23         CommandAuthenticate (InspIRCd* Instance) : Command(Instance,"AUTHENTICATE", 0, 1)
24         {
25                 this->source = "m_sasl.so";
26         }
27
28         CmdResult Handle (const char* const* parameters, int pcnt, User *user)
29         {
30                 if (user->registered != REG_ALL)
31                 {
32                         /* Only allow AUTHENTICATE on unregistered clients */
33                         std::deque<std::string> params;
34                         params.push_back("*");
35                         for (int i = 0; i < pcnt; ++i)
36                                 params.push_back(parameters[0]);
37                 }
38                 return CMD_FAILURE;
39         }
40 };
41
42
43 class ModuleSASL : public Module
44 {
45         CommandAuthenticate* sasl;
46
47  public:
48         
49         ModuleSASL(InspIRCd* Me)
50                 : Module(Me)
51         {
52                 Implementation eventlist[] = { I_OnEvent };
53                 ServerInstance->Modules->Attach(eventlist, this, 1);
54
55                 sasl = new CommandAuthenticate(ServerInstance);
56         }
57
58
59         virtual ~ModuleSASL()
60         {
61         }
62
63         virtual Version GetVersion()
64         {
65                 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
66         }
67
68         virtual void OnEvent(Event *ev)
69         {
70                 GenericCapHandler(ev, "sasl", "sasl");
71
72                 if (ev->GetEventID() == "encap_received")
73                 {
74                         /* Received encap reply, look for AUTHENTICATE */
75                         std::deque<std::string>* parameters = (std::deque<std::string>*)ev->GetData();
76
77                         User* target = ServerInstance->FindNick((*parameters)[0]);
78
79                         if (target)
80                         {
81                                 /* Found a user */
82                                 parameters->pop_front();
83                                 std::string line = irc::stringjoiner(" ", *parameters, 0, parameters->size() - 1).GetJoined();
84                                 target->WriteServ("AUTHENTICATE %s", line.c_str());
85                         }
86                 }
87                 else if (ev->GetEventID() == "account_login")
88                 {
89                         AccountData* ac = (AccountData*)ev->GetData();
90                         ac->user->WriteServ("903 %s :SASL authentication successful", ac->user->nick);
91                 }
92         }
93 };
94
95 MODULE_INIT(ModuleSASL)