summaryrefslogtreecommitdiff
path: root/src/modules/m_sasl.cpp
blob: fc4a75fe3f0af303cbd73de1dd270273116e6649 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*       +------------------------------------+
 *       | Inspire Internet Relay Chat Daemon |
 *       +------------------------------------+
 *
 *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
 * See: http://www.inspircd.org/wiki/index.php/Credits
 *
 * This program is free but copyrighted software; see
 *	    the file COPYING for details.
 *
 * ---------------------------------------------------
 */

#include "inspircd.h"
#include "m_cap.h"

/* $ModDesc: Provides support for atheme SASL via AUTHENTICATE. */

class CommandAuthenticate : public Command
{
 public:
	CommandAuthenticate (InspIRCd* Instance) : Command(Instance,"AUTHENTICATE", 0, 1)
	{
		this->source = "m_sasl.so";
	}

	CmdResult Handle (const char* const* parameters, int pcnt, User *user)
	{
		if (user->registered != REG_ALL)
		{
			/* Only allow AUTHENTICATE on unregistered clients */
			std::deque<std::string> params;
			params.push_back("*");
			for (int i = 0; i < pcnt; ++i)
				params.push_back(parameters[0]);
		}
		return CMD_FAILURE;
	}
};


class ModuleSASL : public Module
{
	CommandAuthenticate* sasl;

 public:
	
	ModuleSASL(InspIRCd* Me)
		: Module(Me)
	{
		Implementation eventlist[] = { I_OnEvent };
		ServerInstance->Modules->Attach(eventlist, this, 1);

		sasl = new CommandAuthenticate(ServerInstance);
	}


	virtual ~ModuleSASL()
	{
	}

	virtual Version GetVersion()
	{
		return Version(1,2,0,1,VF_VENDOR,API_VERSION);
	}

	virtual void OnEvent(Event *ev)
	{
		GenericCapHandler(ev, "sasl", "sasl");

		if (ev->GetEventID() == "encap_received")
		{
			/* Received encap reply, look for AUTHENTICATE */
			std::deque<std::string>* parameters = (std::deque<std::string>*)ev->GetData();

			User* target = ServerInstance->FindNick((*parameters)[0]);

			if (target)
			{
				/* Found a user */
				parameters->pop_front();
				std::string line = irc::stringjoiner(" ", *parameters, 0, parameters->size() - 1).GetJoined();
				target->WriteServ("AUTHENTICATE %s", line.c_str());
			}
		}
	}
};

MODULE_INIT(ModuleSASL)