]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sasl.cpp
fc4a75fe3f0af303cbd73de1dd270273116e6649
[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
17 /* $ModDesc: Provides support for atheme SASL via AUTHENTICATE. */
18
19 class CommandAuthenticate : public Command
20 {
21  public:
22         CommandAuthenticate (InspIRCd* Instance) : Command(Instance,"AUTHENTICATE", 0, 1)
23         {
24                 this->source = "m_sasl.so";
25         }
26
27         CmdResult Handle (const char* const* parameters, int pcnt, User *user)
28         {
29                 if (user->registered != REG_ALL)
30                 {
31                         /* Only allow AUTHENTICATE on unregistered clients */
32                         std::deque<std::string> params;
33                         params.push_back("*");
34                         for (int i = 0; i < pcnt; ++i)
35                                 params.push_back(parameters[0]);
36                 }
37                 return CMD_FAILURE;
38         }
39 };
40
41
42 class ModuleSASL : public Module
43 {
44         CommandAuthenticate* sasl;
45
46  public:
47         
48         ModuleSASL(InspIRCd* Me)
49                 : Module(Me)
50         {
51                 Implementation eventlist[] = { I_OnEvent };
52                 ServerInstance->Modules->Attach(eventlist, this, 1);
53
54                 sasl = new CommandAuthenticate(ServerInstance);
55         }
56
57
58         virtual ~ModuleSASL()
59         {
60         }
61
62         virtual Version GetVersion()
63         {
64                 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
65         }
66
67         virtual void OnEvent(Event *ev)
68         {
69                 GenericCapHandler(ev, "sasl", "sasl");
70
71                 if (ev->GetEventID() == "encap_received")
72                 {
73                         /* Received encap reply, look for AUTHENTICATE */
74                         std::deque<std::string>* parameters = (std::deque<std::string>*)ev->GetData();
75
76                         User* target = ServerInstance->FindNick((*parameters)[0]);
77
78                         if (target)
79                         {
80                                 /* Found a user */
81                                 parameters->pop_front();
82                                 std::string line = irc::stringjoiner(" ", *parameters, 0, parameters->size() - 1).GetJoined();
83                                 target->WriteServ("AUTHENTICATE %s", line.c_str());
84                         }
85                 }
86         }
87 };
88
89 MODULE_INIT(ModuleSASL)