summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7>2008-01-27 00:12:11 +0000
committeraquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7>2008-01-27 00:12:11 +0000
commit20bea3078d67a090ebcca64bf3cdbd7e6ab6adb6 (patch)
tree154357b8fdc476393e110ac48686a1160b508058 /src
parent5773bcf973708ee2d9b0eca42fd0f8076a93f4c9 (diff)
Change API OnOperCompare to OnPassCompare, password hashing is now available for <connect:allow>, <power die= restart=>, <title> (m_customtitle.so), <vhost> (m_vhost.so), this works the same was as for <oper>: load m_password_hash.so (after all hasher modules, of course), and add hash="md5/sha256/whatever" to the relevant tag. Also fix m_callerid.cpp crashing on unload.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8755 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/command_parse.cpp4
-rw-r--r--src/commands/cmd_die.cpp2
-rw-r--r--src/commands/cmd_oper.cpp4
-rw-r--r--src/commands/cmd_pass.cpp2
-rw-r--r--src/commands/cmd_restart.cpp2
-rw-r--r--src/configreader.cpp10
-rw-r--r--src/modules.cpp2
-rw-r--r--src/modules/extra/m_ssl_oper_cert.cpp5
-rw-r--r--src/modules/m_callerid.cpp14
-rw-r--r--src/modules/m_customtitle.cpp3
-rw-r--r--src/modules/m_password_hash.cpp (renamed from src/modules/m_oper_hash.cpp)5
-rw-r--r--src/modules/m_vhost.cpp3
12 files changed, 35 insertions, 21 deletions
diff --git a/src/command_parse.cpp b/src/command_parse.cpp
index 1912f0198..23fa6a6e3 100644
--- a/src/command_parse.cpp
+++ b/src/command_parse.cpp
@@ -27,10 +27,10 @@
#include <dlfcn.h>
#endif
-int InspIRCd::OperPassCompare(const char* data,const char* input, int tagnumber)
+int InspIRCd::PassCompare(Extensible* ex, const char* data,const char* input, const char* hashtype)
{
int MOD_RESULT = 0;
- FOREACH_RESULT_I(this,I_OnOperCompare,OnOperCompare(data, input, tagnumber))
+ FOREACH_RESULT_I(this,I_OnPassCompare,OnPassCompare(ex, data, input, hashtype))
if (MOD_RESULT == 1)
return 0;
if (MOD_RESULT == -1)
diff --git a/src/commands/cmd_die.cpp b/src/commands/cmd_die.cpp
index 7387c7003..0afb6f248 100644
--- a/src/commands/cmd_die.cpp
+++ b/src/commands/cmd_die.cpp
@@ -24,7 +24,7 @@ extern "C" DllExport Command* init_command(InspIRCd* Instance)
*/
CmdResult CommandDie::Handle (const char** parameters, int pcnt, User *user)
{
- if (!strcmp(parameters[0],ServerInstance->Config->diepass))
+ if (!ServerInstance->PassCompare(user, ServerInstance->Config->diepass, parameters[0], ServerInstance->Config->powerhash))
{
std::string diebuf = std::string("*** DIE command from ") + user->nick + "!" + user->ident + "@" + user->dhost + ". Terminating in " + ConvToStr(ServerInstance->Config->DieDelay) + " seconds.";
ServerInstance->Log(SPARSE, diebuf);
diff --git a/src/commands/cmd_oper.cpp b/src/commands/cmd_oper.cpp
index 64d167af2..4d4c54932 100644
--- a/src/commands/cmd_oper.cpp
+++ b/src/commands/cmd_oper.cpp
@@ -45,6 +45,7 @@ CmdResult CommandOper::Handle (const char** parameters, int, User *user)
char ClassName[MAXBUF];
char TheHost[MAXBUF];
char TheIP[MAXBUF];
+ char HashType[MAXBUF];
int j;
bool found = false;
bool type_invalid = false;
@@ -62,9 +63,10 @@ CmdResult CommandOper::Handle (const char** parameters, int, User *user)
ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "password", i, Password, MAXBUF);
ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "type", i, OperType, MAXBUF);
ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "host", i, HostName, MAXBUF);
+ ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "hash", i, HashType, MAXBUF);
match_login = !strcmp(LoginName,parameters[0]);
- match_pass = !ServerInstance->OperPassCompare(Password,parameters[1], i);
+ match_pass = !ServerInstance->PassCompare(user, Password,parameters[1], HashType);
match_hosts = OneOfMatches(TheHost,TheIP,HostName);
if (match_login && match_pass && match_hosts)
diff --git a/src/commands/cmd_pass.cpp b/src/commands/cmd_pass.cpp
index 3661807a9..94a7c6e87 100644
--- a/src/commands/cmd_pass.cpp
+++ b/src/commands/cmd_pass.cpp
@@ -32,7 +32,7 @@ CmdResult CommandPass::Handle (const char** parameters, int, User *user)
return CMD_FAILURE;
strlcpy(user->password,parameters[0],63);
- if (a->GetPass() == parameters[0])
+ if (!ServerInstance->PassCompare(user, a->GetPass().c_str(), parameters[0], a->GetHash().c_str()))
{
user->haspassed = true;
}
diff --git a/src/commands/cmd_restart.cpp b/src/commands/cmd_restart.cpp
index 7d9921d4c..b22bb774b 100644
--- a/src/commands/cmd_restart.cpp
+++ b/src/commands/cmd_restart.cpp
@@ -22,7 +22,7 @@ extern "C" DllExport Command* init_command(InspIRCd* Instance)
CmdResult CommandRestart::Handle (const char** parameters, int, User *user)
{
ServerInstance->Log(DEFAULT,"Restart: %s",user->nick);
- if (!strcmp(parameters[0],ServerInstance->Config->restartpass))
+ if (!ServerInstance->PassCompare(user, ServerInstance->Config->restartpass, parameters[0], ServerInstance->Config->powerhash))
{
ServerInstance->SNO->WriteToSnoMask('A', "RESTART command from %s!%s@%s, restarting server.",user->nick,user->ident,user->host);
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 64ba689a7..a9c41be7b 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -575,6 +575,7 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
const char* parent = values[13].GetString();
int maxchans = values[14].GetInteger();
unsigned long limit = values[15].GetInteger();
+ const char* hashtype = values[16].GetString();
/*
* duplicates check: Now we don't delete all connect classes on rehash, we need to ensure we don't add dupes.
@@ -619,7 +620,7 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
{
if (*allow)
{
- ConnectClass* c = new ConnectClass(name, timeout, flood, allow, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans);
+ ConnectClass* c = new ConnectClass(name, timeout, flood, allow, pingfreq, password, hashtype, threshold, sendq, recvq, localmax, globalmax, maxchans);
c->limit = limit;
c->SetPort(port);
conf->Classes.push_back(c);
@@ -817,6 +818,7 @@ void ServerConfig::Read(bool bail, User* user, int pass)
{"files", "rules", "", new ValueContainerChar (this->rules), DT_CHARPTR, ValidateRules},
{"power", "diepass", "", new ValueContainerChar (this->diepass), DT_CHARPTR, ValidateNotEmpty},
{"power", "pause", "", new ValueContainerInt (&this->DieDelay), DT_INTEGER, NoValidation},
+ {"power", "hash", "", new ValueContainerChar (this->powerhash), DT_CHARPTR, NoValidation},
{"power", "restartpass", "", new ValueContainerChar (this->restartpass), DT_CHARPTR, ValidateNotEmpty},
{"options", "prefixquit", "", new ValueContainerChar (this->PrefixQuit), DT_CHARPTR, NoValidation},
{"options", "suffixquit", "", new ValueContainerChar (this->SuffixQuit), DT_CHARPTR, NoValidation},
@@ -867,17 +869,17 @@ void ServerConfig::Read(bool bail, User* user, int pass)
{"connect",
{"allow", "deny", "password", "timeout", "pingfreq", "flood",
"threshold", "sendq", "recvq", "localmax", "globalmax", "port",
- "name", "parent", "maxchans", "limit",
+ "name", "parent", "maxchans", "limit", "hash",
NULL},
{"", "", "", "", "120", "",
"", "", "", "3", "3", "0",
- "", "", "0", "0",
+ "", "", "0", "0", "",
NULL},
{DT_IPADDRESS|DT_ALLOW_WILD,
DT_IPADDRESS|DT_ALLOW_WILD,
DT_CHARPTR, DT_INTEGER, DT_INTEGER, DT_INTEGER,
DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER,
- DT_NOSPACES, DT_NOSPACES, DT_INTEGER, DT_INTEGER},
+ DT_NOSPACES, DT_NOSPACES, DT_INTEGER, DT_INTEGER, DT_CHARPTR},
InitConnect, DoConnect, DoneConnect},
{"uline",
diff --git a/src/modules.cpp b/src/modules.cpp
index 2aae2a00d..cd869585f 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -151,7 +151,7 @@ int Module::OnChangeLocalUserGECOS(User*, const std::string&) { return 0; }
int Module::OnLocalTopicChange(User*, Channel*, const std::string&) { return 0; }
void Module::OnEvent(Event*) { return; }
char* Module::OnRequest(Request*) { return NULL; }
-int Module::OnOperCompare(const std::string&, const std::string&, int) { return 0; }
+int Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { return 0; }
void Module::OnGlobalOper(User*) { }
void Module::OnPostConnect(User*) { }
int Module::OnAddBan(User*, Channel*, const std::string &) { return 0; }
diff --git a/src/modules/extra/m_ssl_oper_cert.cpp b/src/modules/extra/m_ssl_oper_cert.cpp
index 074a75713..f82537c95 100644
--- a/src/modules/extra/m_ssl_oper_cert.cpp
+++ b/src/modules/extra/m_ssl_oper_cert.cpp
@@ -112,7 +112,6 @@ class ModuleOperSSLCert : public Module
return false;
}
-
virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, User *user, bool validated, const std::string &original_line)
{
irc::string cmd = command.c_str();
@@ -125,6 +124,7 @@ class ModuleOperSSLCert : public Module
std::string Password;
std::string OperType;
std::string HostName;
+ std::string HashType;
std::string FingerPrint;
bool SSLOnly;
char* dummy;
@@ -140,12 +140,13 @@ class ModuleOperSSLCert : public Module
Password = cf->ReadValue("oper", "password", i);
OperType = cf->ReadValue("oper", "type", i);
HostName = cf->ReadValue("oper", "host", i);
+ HashType = cf->ReadValue("oper", "hash", i);
FingerPrint = cf->ReadValue("oper", "fingerprint", i);
SSLOnly = cf->ReadFlag("oper", "sslonly", i);
if (SSLOnly || !FingerPrint.empty())
{
- if ((!strcmp(LoginName.c_str(),parameters[0])) && (!ServerInstance->OperPassCompare(Password.c_str(),parameters[1],i)) && (OneOfMatches(TheHost,TheIP,HostName.c_str())))
+ if ((!strcmp(LoginName.c_str(),parameters[0])) && (!ServerInstance->PassCompare(user, Password.c_str(),parameters[1], HashType.c_str())) && (OneOfMatches(TheHost,TheIP,HostName.c_str())))
{
if (SSLOnly && !user->GetExt("ssl", dummy))
{
diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp
index 6d7d8413f..d3df1948b 100644
--- a/src/modules/m_callerid.cpp
+++ b/src/modules/m_callerid.cpp
@@ -222,13 +222,13 @@ public:
delete myumode;
throw new ModuleException("Could not add usermode and command!");
}
- Implementation eventlist[] = { I_OnRehash, I_OnUserPreNick, I_OnUserQuit, I_On005Numeric, I_OnUserPreNotice, I_OnUserPreMessage };
- ServerInstance->Modules->Attach(eventlist, this, 6);
+ Implementation eventlist[] = { I_OnRehash, I_OnUserPreNick, I_OnUserQuit, I_On005Numeric, I_OnUserPreNotice, I_OnUserPreMessage, I_OnCleanup };
+ ServerInstance->Modules->Attach(eventlist, this, 7);
}
~ModuleCallerID()
{
- delete mycommand;
+ delete myumode;
}
Version GetVersion()
@@ -279,6 +279,14 @@ public:
return 0;
}
+ void OnCleanup(int type, void* item)
+ {
+ if (type != TYPE_USER) return;
+ User* u = (User*)item;
+ /* Cleanup only happens on unload (before dtor), so keep this O(n) instead of O(n^2) which deferring to OnUserQuit would do. */
+ RemoveData(u);
+ }
+
int OnUserPreNick(User* user, const std::string& newnick)
{
if (!tracknick)
diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp
index e3d84e10f..0caa2d6f5 100644
--- a/src/modules/m_customtitle.cpp
+++ b/src/modules/m_customtitle.cpp
@@ -59,11 +59,12 @@ bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
{
std::string name = Conf.ReadValue("title", "name", "", i);
std::string pass = Conf.ReadValue("title", "password", "", i);
+ std::string hash = Conf.ReadValue("title", "hash", "", i);
std::string host = Conf.ReadValue("title", "host", "*@*", i);
std::string title = Conf.ReadValue("title", "title", "", i);
std::string vhost = Conf.ReadValue("title", "vhost", "", i);
- if (!strcmp(name.c_str(),parameters[0]) && !strcmp(pass.c_str(),parameters[1]) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
+ if (!strcmp(name.c_str(),parameters[0]) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1], hash.c_str()) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
{
std::string* text;
user->GetExt("ctitle", text);
diff --git a/src/modules/m_oper_hash.cpp b/src/modules/m_password_hash.cpp
index e0ea8246a..45f986be8 100644
--- a/src/modules/m_oper_hash.cpp
+++ b/src/modules/m_password_hash.cpp
@@ -108,7 +108,7 @@ class ModuleOperHash : public Module
mycommand = new CommandMkpasswd(ServerInstance, this, hashers, names);
ServerInstance->AddCommand(mycommand);
- Implementation eventlist[] = { I_OnRehash, I_OnOperCompare };
+ Implementation eventlist[] = { I_OnRehash, I_OnPassCompare };
ServerInstance->Modules->Attach(eventlist, this, 2);
}
@@ -127,10 +127,9 @@ class ModuleOperHash : public Module
Conf = new ConfigReader(ServerInstance);
}
- virtual int OnOperCompare(const std::string &data, const std::string &input, int tagnumber)
+ virtual int OnPassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype)
{
/* First, lets see what hash theyre using on this oper */
- std::string hashtype = Conf->ReadValue("oper", "hash", tagnumber);
hashymodules::iterator x = hashers.find(hashtype.c_str());
/* Is this a valid hash name? (case insensitive) */
diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp
index 130a8acc5..371f99dfa 100644
--- a/src/modules/m_vhost.cpp
+++ b/src/modules/m_vhost.cpp
@@ -35,8 +35,9 @@ class CommandVhost : public Command
std::string mask = Conf->ReadValue("vhost","host",index);
std::string username = Conf->ReadValue("vhost","user",index);
std::string pass = Conf->ReadValue("vhost","pass",index);
+ std::string hash = Conf->ReadValue("vhost","hash",index);
- if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
+ if ((!strcmp(parameters[0],username.c_str())) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1], hash.c_str()))
{
if (!mask.empty())
{