mirror of
https://github.com/anope/anope.git
synced 2026-07-07 05:13:12 +02:00
Added ns_resetpass which can be used to reset user passwords by email, very useful if you're using encryption
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2685 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
@@ -97,7 +97,7 @@ class CommandNSConfirm : public Command
|
||||
CommandReturn DoConfirm(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
NickRequest *nr = NULL;
|
||||
const char *passcode = params.size() ? params[0].c_str() : NULL;
|
||||
const char *passcode = !params.empty() ? params[0].c_str() : NULL;
|
||||
|
||||
nr = findrequestnick(u->nick);
|
||||
|
||||
@@ -105,7 +105,7 @@ class CommandNSConfirm : public Command
|
||||
{
|
||||
if (!passcode)
|
||||
{
|
||||
notice_lang(Config.s_NickServ, u, NICK_CONFIRM_INVALID);
|
||||
this->OnSyntaxError(u, "");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
@@ -143,6 +143,7 @@ class CommandNSConfirm : public Command
|
||||
ActuallyConfirmNick(u, nr, false);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
public:
|
||||
CommandNSConfirm(const std::string &cmdn, int min, int max) : Command(cmdn, min, max)
|
||||
{
|
||||
@@ -161,6 +162,11 @@ class CommandNSConfirm : public Command
|
||||
notice_help(Config.s_NickServ, u, NICK_HELP_CONFIRM_OPER);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(User *u, const ci::string &subcommand)
|
||||
{
|
||||
notice_lang(Config.s_NickServ, u, NICK_CONFIRM_INVALID);
|
||||
}
|
||||
};
|
||||
|
||||
class CommandNSRegister : public CommandNSConfirm
|
||||
@@ -366,7 +372,7 @@ class NSRegister : public Module
|
||||
this->SetType(CORE);
|
||||
|
||||
this->AddCommand(NICKSERV, new CommandNSRegister());
|
||||
this->AddCommand(NICKSERV, new CommandNSConfirm("CONFIRM", 0, 1));
|
||||
this->AddCommand(NICKSERV, new CommandNSConfirm("CONFIRM", 1, 1));
|
||||
this->AddCommand(NICKSERV, new CommandNSResend());
|
||||
|
||||
ModuleManager::Attach(I_OnNickServHelp, this);
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
/* NickServ core functions
|
||||
*
|
||||
* (C) 2003-2009 Anope Team
|
||||
* Contact us at team@anope.org
|
||||
*
|
||||
* Please read COPYING and README for further details.
|
||||
*
|
||||
* Based on the original code of Epona by Lara.
|
||||
* Based on the original code of Services by Andy Church.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
|
||||
class CommandNSResetPass : public Command
|
||||
{
|
||||
public:
|
||||
CommandNSResetPass() : Command("RESETPASS", 1, 1)
|
||||
{
|
||||
}
|
||||
|
||||
CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
NickAlias *na;
|
||||
|
||||
if (Config.RestrictMail && !u->nc->HasCommand("nickserv/resetpass"))
|
||||
notice_lang(Config.s_NickServ, u, ACCESS_DENIED);
|
||||
if (!(na = findnick(params[0].c_str())))
|
||||
notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, params[0].c_str());
|
||||
else if (na->HasFlag(NS_FORBIDDEN))
|
||||
notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
|
||||
else
|
||||
{
|
||||
char buf[BUFSIZE], message[BUFSIZE];
|
||||
snprintf(buf, sizeof(buf), getstring(na, NICK_RESETPASS_SUBJECT), na->nick);
|
||||
|
||||
MailInfo *mail = MailBegin(u, na->nc, buf, Config.s_NickServ);
|
||||
if (!mail)
|
||||
return MOD_CONT;
|
||||
|
||||
char passcode[20];
|
||||
int min = 1, max = 62;
|
||||
int chars[] = {
|
||||
' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
|
||||
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
|
||||
'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
|
||||
'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||||
};
|
||||
|
||||
int idx;
|
||||
for (idx = 0; idx < 20; ++idx)
|
||||
passcode[idx] = chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min];
|
||||
passcode[idx] = '\0';
|
||||
|
||||
snprintf(message, sizeof(message), getstring(na, NICK_RESETPASS_MESSAGE), na->nick, Config.s_NickServ, passcode, Config.NetworkName);
|
||||
fprintf(mail->pipe, "%s", message);
|
||||
fprintf(mail->pipe, "\n.\n");
|
||||
MailEnd(mail);
|
||||
|
||||
char *c;
|
||||
time_t *t;
|
||||
if (na->nc->GetExt("ns_resetpass_code", c))
|
||||
{
|
||||
delete [] c;
|
||||
na->nc->Shrink("ns_resetpass_code");
|
||||
}
|
||||
if (na->nc->GetExt("ns_resetpass_time", t))
|
||||
{
|
||||
delete t;
|
||||
na->nc->Shrink("ns_resetpass_time");
|
||||
}
|
||||
|
||||
na->nc->Extend("ns_resetpass_code", sstrdup(passcode));
|
||||
t = new time_t(time(NULL));
|
||||
na->nc->Extend("ns_resetpass_time", t);
|
||||
|
||||
alog("%s: %s!%s@%s used RESETPASS on %s (%s)", Config.s_NickServ, u->nick, u->GetIdent().c_str(), u->host, na->nick, na->nc->display);
|
||||
notice_lang(Config.s_NickServ, u, NICK_RESETPASS_COMPLETE, na->nick);
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
bool OnHelp(User *u, const ci::string &subcommand)
|
||||
{
|
||||
notice_help(Config.s_NickServ, u, NICK_HELP_RESETPASS);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(User *u, const ci::string &subcommand)
|
||||
{
|
||||
syntax_error(Config.s_NickServ, u, "RESETPASS", NICK_RESETPASS_SYNTAX);
|
||||
}
|
||||
};
|
||||
|
||||
class NSResetPass : public Module
|
||||
{
|
||||
public:
|
||||
NSResetPass(const std::string &modname, const std::string &creator) : Module(modname, creator)
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
this->SetVersion("$Id$");
|
||||
this->SetType(CORE);
|
||||
|
||||
if (!Config.UseMail)
|
||||
throw ModuleException("Not using mail.");
|
||||
|
||||
this->AddCommand(NICKSERV, new CommandNSResetPass());
|
||||
|
||||
Implementation i[] = { I_OnNickServHelp, I_OnDelCore, I_OnPreCommand };
|
||||
ModuleManager::Attach(i, this, 3);
|
||||
}
|
||||
|
||||
void OnNickServHelp(User *u)
|
||||
{
|
||||
notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_RESETPASS);
|
||||
}
|
||||
|
||||
void OnDelCore(NickCore *nc)
|
||||
{
|
||||
char *c;
|
||||
time_t *t;
|
||||
|
||||
if (nc->GetExt("ns_resetpass_code", c))
|
||||
{
|
||||
delete [] c;
|
||||
nc->Shrink("ns_resetpass_code");
|
||||
}
|
||||
if (nc->GetExt("ns_resetpass_time", t))
|
||||
{
|
||||
delete t;
|
||||
nc->Shrink("ns_resetpass_time");
|
||||
}
|
||||
}
|
||||
|
||||
EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
if (service == Config.s_NickServ && command == "CONFIRM" && !params.empty())
|
||||
{
|
||||
NickAlias *na = findnick(u->nick);
|
||||
char *c;
|
||||
time_t *t;
|
||||
|
||||
if (na && na->nc->GetExt("ns_resetpass_code", c) && na->nc->GetExt("ns_resetpass_time", t))
|
||||
{
|
||||
if (*t < time(NULL) - 3600)
|
||||
{
|
||||
delete [] c;
|
||||
delete t;
|
||||
na->nc->Shrink("ns_resetpass_code");
|
||||
na->nc->Shrink("ns_resetpass_time");
|
||||
notice_lang(Config.s_NickServ, u, NICK_CONFIRM_EXPIRED);
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
std::string passcode = params[0].c_str();
|
||||
if (passcode == c)
|
||||
{
|
||||
delete [] c;
|
||||
delete t;
|
||||
na->nc->Shrink("ns_resetpass_code");
|
||||
na->nc->Shrink("ns_resetpass_time");
|
||||
|
||||
u->UpdateHost();
|
||||
if (na->last_realname)
|
||||
delete [] na->last_realname;
|
||||
na->last_realname = sstrdup(u->realname);
|
||||
na->last_seen = time(NULL);
|
||||
u->nc = na->nc;
|
||||
ircdproto->SendAccountLogin(u, u->nc);
|
||||
ircdproto->SetAutoIdentificationToken(u);
|
||||
FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(u));
|
||||
|
||||
alog("%s: %s!%s@%s used CONFIRM with RESETPASS to forcefully identify to %s", Config.s_NickServ, u->nick, u->GetIdent().c_str(), u->host, na->nick);
|
||||
|
||||
notice_lang(Config.s_NickServ, u, NICK_CONFIRM_SUCCESS, Config.s_NickServ);
|
||||
|
||||
if (ircd->vhost)
|
||||
do_on_id(u);
|
||||
if (Config.NSModeOnID)
|
||||
do_setmodes(u);
|
||||
check_memos(u);
|
||||
}
|
||||
else
|
||||
{
|
||||
alog("%s: Invalid CONFIRM passcode for %s from %s!%s@%s", Config.s_NickServ, na->nick, u->nick, u->GetIdent().c_str(), u->host);
|
||||
notice_lang(Config.s_NickServ, u, NICK_CONFIRM_INVALID);
|
||||
bad_password(u);
|
||||
}
|
||||
|
||||
return EVENT_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
MODULE_INIT(NSResetPass)
|
||||
Reference in New Issue
Block a user