diff options
author | Adam <Adam@anope.org> | 2010-06-19 11:54:08 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-06-19 11:54:08 -0400 |
commit | 52058fe87b4b0475b1775198c725af14e540d355 (patch) | |
tree | c3597d6411a006ffbb670d2ce761101b9640e9b6 /src/core/enc_none.cpp | |
parent | 43e951aed54f838ba55a4c1552214773aee2fb2f (diff) | |
parent | df9d291bcba9788e51d11424ebaf6f05c26cc80f (diff) |
Merge remote branch 'origin/1.9.3' into 1.9
Diffstat (limited to 'src/core/enc_none.cpp')
-rw-r--r-- | src/core/enc_none.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/core/enc_none.cpp b/src/core/enc_none.cpp new file mode 100644 index 000000000..280c86bd2 --- /dev/null +++ b/src/core/enc_none.cpp @@ -0,0 +1,78 @@ +/* Module for plain text encryption. + * + * (C) 2003-2010 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 std::string &modname, const std::string &creator) : Module(modname, creator) + { + this->SetAuthor("Anope"); + this->SetVersion(VERSION_STRING); + this->SetType(ENCRYPTION); + + ModuleManager::Attach(I_OnEncrypt, this); + ModuleManager::Attach(I_OnEncryptInPlace, this); + ModuleManager::Attach(I_OnDecrypt, this); + ModuleManager::Attach(I_OnCheckPassword, this); + } + + EventReturn OnEncrypt(const std::string &src, std::string &dest) + { + std::string buf = "plain:"; + char cpass[1000]; + b64_encode(src.c_str(), src.size(), cpass, 1000); + buf.append(cpass); + Alog(LOG_DEBUG_2) << "(enc_none) hashed password from [" << src << "] to [" << buf << "]"; + dest.assign(buf); + return EVENT_ALLOW; + } + + EventReturn OnEncryptInPlace(std::string &buf) + { + return this->OnEncrypt(buf, buf); + } + + EventReturn OnDecrypt(const std::string &hashm, const std::string &src, std::string &dest) + { + if (hashm != "plain") + return EVENT_CONTINUE; + char cpass[1000]; + memset(&cpass, 0, sizeof(cpass)); + size_t pos = src.find(":"); + std::string buf(src.begin()+pos+1, src.end()); + b64_decode(buf.c_str(), cpass, 1000); + dest.assign(cpass); + return EVENT_ALLOW; + } + + EventReturn OnCheckPassword(const std::string &hashm, std::string &plaintext, std::string &password) + { + if (hashm != "plain") + return EVENT_CONTINUE; + std::string buf; + this->OnEncrypt(plaintext, buf); + if(!password.compare(buf)) + { + /* if we are NOT the first module in the list, + * we want to re-encrypt the pass with the new encryption + */ + if (Config.EncModuleList.front().compare(this->name)) + { + enc_encrypt(plaintext, password); + } + return EVENT_ALLOW; + } + return EVENT_STOP; + } + +}; + +MODULE_INIT(ENone) |