summaryrefslogtreecommitdiff
path: root/modules/core/enc_none.cpp
blob: c1b403235e3e7d61d7160a33bfd1bc19f6cc7daf (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
/* Module for plain text encryption.
 *
 * (C) 2003-2011 Anope Team
 * Contact us at team@anope.org
 *
 * This program is free but copyrighted software; see the file COPYING for
 * details.
 */

#include "module.h"

class ENone : public Module
{
 public:
	ENone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
	{
		this->SetAuthor("Anope");
		this->SetType(ENCRYPTION);

		Implementation i[] = { I_OnEncrypt, I_OnDecrypt, I_OnCheckAuthentication };
		ModuleManager::Attach(i, this, 3);
	}

	EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest)
	{
		Anope::string buf = "plain:";
		Anope::string cpass;
		b64_encode(src, cpass);
		buf += cpass;
		Log(LOG_DEBUG_2) << "(enc_none) hashed password from [" << src << "] to [" << buf << "]";
		dest = buf;
		return EVENT_ALLOW;
	}

	EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest)
	{
		if (!hashm.equals_cs("plain"))
			return EVENT_CONTINUE;
		size_t pos = src.find(':');
		Anope::string buf = src.substr(pos + 1);
		b64_decode(buf, dest);
		return EVENT_ALLOW;
	}

	EventReturn OnCheckAuthentication(User *u, Command *c, const std::vector<Anope::string> &params, const Anope::string &account, const Anope::string &password)
	{
		NickAlias *na = findnick(account);
		NickCore *nc = na ? na->nc : NULL;
		if (na == NULL)
			return EVENT_CONTINUE;

		size_t pos = nc->pass.find(':');
		if (pos == Anope::string::npos)
			return EVENT_CONTINUE;
		Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
		if (!hash_method.equals_cs("plain"))
			return EVENT_CONTINUE;

		Anope::string buf;
		this->OnEncrypt(password, buf);
		if (nc->pass.equals_cs(buf))
		{
			/* if we are NOT the first module in the list,
			 * we want to re-encrypt the pass with the new encryption
			 */
			if (!this->name.equals_ci(Config->EncModuleList.front()))
				enc_encrypt(password, nc->pass);
			return EVENT_ALLOW;
		}

		return EVENT_CONTINUE;
	}
};

MODULE_INIT(ENone)