Fixed at last.

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5640 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2006-11-03 17:18:30 +00:00
parent 252301f34d
commit 2d02925382

View File

@ -61,12 +61,12 @@ public:
void Implements(char* List) void Implements(char* List)
{ {
List[I_OnRequest] = List[I_OnRehash] = List[I_OnPostCommand] = 1; List[I_OnRequest] = List[I_OnRehash] = List[I_OnPreCommand] = 1;
} }
virtual void OnPostCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, CmdResult result, const std::string &original_line) virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
{ {
if ((result == CMD_FAILURE) && (command == "OPER")) if ((validated) && (command == "OPER"))
{ {
if (LookupOper(user, parameters[0], parameters[1])) if (LookupOper(user, parameters[0], parameters[1]))
{ {
@ -78,6 +78,7 @@ public:
return 1; return 1;
} }
} }
return 0;
} }
bool LookupOper(userrec* user, const std::string &username, const std::string &password) bool LookupOper(userrec* user, const std::string &username, const std::string &password)
@ -85,7 +86,7 @@ public:
Module* target; Module* target;
target = Srv->FindFeature("SQL"); target = Srv->FindFeature("SQL");
if (target) if (target)
{ {
SQLrequest req = SQLreq(this, target, databaseid, "SELECT username, password, hostname, type FROM ircd_opers WHERE username = '?' AND password=md5('?')", username, password); SQLrequest req = SQLreq(this, target, databaseid, "SELECT username, password, hostname, type FROM ircd_opers WHERE username = '?' AND password=md5('?')", username, password);
@ -102,6 +103,9 @@ public:
ServerInstance->Log(DEBUG, "Sent query, got given ID %lu", req.id); ServerInstance->Log(DEBUG, "Sent query, got given ID %lu", req.id);
AssociateUser(this, SQLutils, req.id, user).Send(); AssociateUser(this, SQLutils, req.id, user).Send();
user->Extend("oper_user", strdup(username.c_str()));
user->Extend("oper_pass", strdup(password.c_str()));
return true; return true;
} }
@ -131,6 +135,12 @@ public:
userrec* user = GetAssocUser(this, SQLutils, res->id).S().user; userrec* user = GetAssocUser(this, SQLutils, res->id).S().user;
UnAssociate(this, SQLutils, res->id).S(); UnAssociate(this, SQLutils, res->id).S();
char* tried_user = NULL;
char* tried_pass = NULL;
user->GetExt("oper_user", tried_user);
user->GetExt("oper_pass", tried_pass);
if (user) if (user)
{ {
@ -171,8 +181,14 @@ public:
* we should have already checked the o:lines so now we need an * we should have already checked the o:lines so now we need an
* "insufficient awesomeness" (invalid credentials) error * "insufficient awesomeness" (invalid credentials) error
*/ */
if (tried_user && tried_pass)
LoginFail(user, row["username"].d, row["password"].d); {
LoginFail(user, tried_user, tried_pass);
free(tried_user);
free(tried_pass);
user->Shrink("oper_user");
user->Shrink("oper_pass");
}
} }
} }
else else
@ -183,7 +199,15 @@ public:
*/ */
ServerInstance->Log(DEBUG, "Query failed: %s", res->error.Str()); ServerInstance->Log(DEBUG, "Query failed: %s", res->error.Str());
LoginFail(user, row["username"].d, row["password"].d); if (tried_user && tried_pass)
{
LoginFail(user, tried_user, tried_pass);
free(tried_user);
free(tried_pass);
user->Shrink("oper_user");
user->Shrink("oper_pass");
}
} }
} }
else else
@ -195,17 +219,17 @@ public:
} }
ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId()); ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId());
return NULL; return NULL;
} }
void LoginFail(userrec* user, const std::string &user, const std::string &pass) void LoginFail(userrec* user, const std::string &username, const std::string &pass)
{ {
command_t* oper_command = ServerInstance->Parser->GetCommand("OPER"); command_t* oper_command = ServerInstance->Parser->GetHandler("OPER");
if (oper_command) if (oper_command)
{ {
const char* params = { user.c_str(), pass.c_str() }; const char* params[] = { username.c_str(), pass.c_str() };
oper_command->Handle(params, 2, user); oper_command->Handle(params, 2, user);
} }
else else