diff options
author | adam- <adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-08-04 01:56:14 +0000 |
---|---|---|
committer | adam- <adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-08-04 01:56:14 +0000 |
commit | ce664a160b1c1d4c75de5ba1867c96a0698326fd (patch) | |
tree | 313d7e88fdbb98b4d45917cbd6eb2d3aa36a661e /src | |
parent | 0d7e0274a4e10bcd2b9410d907ff3fec9202d336 (diff) |
Fixed autoid
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2404 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ns_group.c | 16 | ||||
-rw-r--r-- | src/core/ns_identify.c | 15 | ||||
-rw-r--r-- | src/core/ns_logout.c | 2 | ||||
-rw-r--r-- | src/core/ns_register.c | 17 | ||||
-rw-r--r-- | src/protocol/bahamut.c | 46 | ||||
-rw-r--r-- | src/protocol/inspircd11.c | 43 | ||||
-rw-r--r-- | src/protocol/inspircd12.cpp | 50 | ||||
-rw-r--r-- | src/protocol/ratbox.c | 41 | ||||
-rw-r--r-- | src/protocol/unreal32.c | 54 | ||||
-rw-r--r-- | src/users.c | 34 |
10 files changed, 252 insertions, 66 deletions
diff --git a/src/core/ns_group.c b/src/core/ns_group.c index 3a3b68777..5c3cde993 100644 --- a/src/core/ns_group.c +++ b/src/core/ns_group.c @@ -28,13 +28,8 @@ class CommandNSGroup : public Command CommandReturn Execute(User *u, std::vector<ci::string> ¶ms) { NickAlias *na, *target; - NickCore *nc; const char *nick = params[0].c_str(); const char *pass = params[1].c_str(); - int i; - char tsbuf[16]; - char modes[512]; - int len; std::list<std::pair<std::string, std::string> >::iterator it; if (NSEmailReg && findrequestnick(u->nick)) @@ -131,21 +126,12 @@ class CommandNSGroup : public Command u->nc = na->nc; FOREACH_MOD(I_OnNickGroup, OnNickGroup(u, target)); + ircdproto->SetAutoIdentificationToken(u); alog("%s: %s!%s@%s makes %s join group of %s (%s) (e-mail: %s)", s_NickServ, u->nick, u->GetIdent().c_str(), u->host, u->nick, target->nick, target->nc->display, (target->nc->email ? target->nc->email : "none")); notice_lang(s_NickServ, u, NICK_GROUP_JOINED, target->nick); u->lastnickreg = time(NULL); - snprintf(tsbuf, sizeof(tsbuf), "%lu", static_cast<unsigned long>(u->timestamp)); - if (ircd->modeonreg) - { - len = strlen(ircd->modeonreg); - strncpy(modes, ircd->modeonreg, 512); - if (ircd->tsonmode) - common_svsmode(u, modes, tsbuf); - else - common_svsmode(u, modes, NULL); - } check_memos(u); } diff --git a/src/core/ns_identify.c b/src/core/ns_identify.c index e2bacf321..eb47101d8 100644 --- a/src/core/ns_identify.c +++ b/src/core/ns_identify.c @@ -32,9 +32,6 @@ class CommandNSIdentify : public Command NickAlias *na; NickRequest *nr; int res; - char tsbuf[16]; - char modes[512]; - int len; if (!(na = findnick(u->nick))) { @@ -74,18 +71,8 @@ class CommandNSIdentify : public Command na->last_seen = time(NULL); u->nc = na->nc; - snprintf(tsbuf, sizeof(tsbuf), "%lu", static_cast<unsigned long>(u->timestamp)); - - if (ircd->modeonreg) - { - len = strlen(ircd->modeonreg); - strncpy(modes, ircd->modeonreg, 512); - if (ircd->tsonmode) - common_svsmode(u, modes, tsbuf); - else - common_svsmode(u, modes, ""); - } ircdproto->SendAccountLogin(u, u->nc); + ircdproto->SetAutoIdentificationToken(u); FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(u)); diff --git a/src/core/ns_logout.c b/src/core/ns_logout.c index 6a7a6e337..ea306e387 100644 --- a/src/core/ns_logout.c +++ b/src/core/ns_logout.c @@ -58,7 +58,7 @@ class CommandNSLogout : public Command na->status &= ~(NS_IDENTIFIED | NS_RECOGNIZED); } - if (ircd->modeonreg) + if (ircd->modeonunreg) common_svsmode(u2, ircd->modeonunreg, "1"); u2->isSuperAdmin = 0; /* Dont let people logout and remain a SuperAdmin */ diff --git a/src/core/ns_register.c b/src/core/ns_register.c index 6c7f7af3c..9ed66529b 100644 --- a/src/core/ns_register.c +++ b/src/core/ns_register.c @@ -34,10 +34,7 @@ class CommandNSConfirm : public Command return MOD_CONT; } - int len; - char tsbuf[16]; char tmp_pass[PASSMAX]; - char modes[512]; memcpy(na->nc->pass, nr->password, PASSMAX); na->status = static_cast<int16>(NS_IDENTIFIED | NS_RECOGNIZED); @@ -77,6 +74,7 @@ class CommandNSConfirm : public Command notice_lang(s_NickServ, u, NICK_REGISTERED_NO_MASK, u->nick); ircdproto->SendAccountLogin(u, u->nc); + ircdproto->SetAutoIdentificationToken(u); FOREACH_MOD(I_OnNickRegister, OnNickRegister(u)); @@ -84,19 +82,6 @@ class CommandNSConfirm : public Command notice_lang(s_NickServ, u, NICK_PASSWORD_IS, tmp_pass); u->lastnickreg = time(NULL); - if (ircd->modeonreg) - { - len = strlen(ircd->modeonreg); - strncpy(modes, ircd->modeonreg, 512); - - if (ircd->tsonmode) - { - snprintf(tsbuf, sizeof(tsbuf), "%lu", static_cast<unsigned long>(u->timestamp)); - common_svsmode(u, modes, tsbuf); - } - else - common_svsmode(u, modes, NULL); - } } else notice_lang(s_NickServ, u, NICK_FORCE_REG, nr->nick); diff --git a/src/protocol/bahamut.c b/src/protocol/bahamut.c index bc1a7b01f..7ebdae106 100644 --- a/src/protocol/bahamut.c +++ b/src/protocol/bahamut.c @@ -75,9 +75,7 @@ IRCDVar myIrcd[] = { NULL, /* Mode to unset for an owner */ NULL, /* Mode to set for channel admin */ NULL, /* Mode to unset for channel admin */ - "+rd", /* Mode On Reg */ - "-r+d", /* Mode on UnReg */ - "+d", /* Mode on Nick Change */ + "-r+d", /* Mode on UnReg */ 1, /* Supports SGlines */ 1, /* Supports SQlines */ 1, /* Supports SZlines */ @@ -709,6 +707,29 @@ class BahamutIRCdProto : public IRCDProto bahamut_cmd_svinfo(); bahamut_cmd_burst(); } + + void SetAutoIdentificationToken(User *u) + { + int *c; + char svidbuf[15]; + + if (!u->nc) + return; + + srand(time(NULL)); + snprintf(svidbuf, sizeof(svidbuf), "%i", rand()); + + if (u->nc->GetExt("authenticationtoken", c)) + { + delete [] c; + u->nc->Shrink("authenticationtoken"); + } + + u->nc->Extend("authenticationtoken", sstrdup(svidbuf)); + + common_svsmode(u, "+rd", svidbuf); + } + } ircd_proto; @@ -746,6 +767,11 @@ int anope_event_nick(const char *source, int ac, const char **av) strtoul(av[2], NULL, 10), strtoul(av[8], NULL, 0), NULL, NULL); if (user) { + /* Check to see if the user should be identified because their + * services id matches the one in their nickcore + */ + user->CheckAuthenticationToken(av[7]); + ircdproto->ProcessUsermodes(user, 1, &av[3]); } } else { @@ -1046,7 +1072,21 @@ class ProtoBahamut : public Module pmodule_ircd_proto(&ircd_proto); moduleAddIRCDMsgs(); + + ModuleManager::Attach(I_OnDelCore, this); } + + void OnDelCore(NickCore *nc) + { + char *c; + + if (nc->GetExt("authenticationtoken", c)) + { + delete [] c; + nc->Shrink("authenticationtoken"); + } + } + }; MODULE_INIT("bahamut", ProtoBahamut) diff --git a/src/protocol/inspircd11.c b/src/protocol/inspircd11.c index 0aa2321b4..b4f811e36 100644 --- a/src/protocol/inspircd11.c +++ b/src/protocol/inspircd11.c @@ -84,9 +84,7 @@ IRCDVar myIrcd[] = { "-q", /* Mode to unset for an owner */ "+a", /* Mode to set for channel admin */ "-a", /* Mode to unset for channel admin */ - "+r", /* Mode On Reg */ - "-r", /* Mode on UnReg */ - "-r", /* Mode on Nick Change */ + "-r", /* Mode on UnReg */ 1, /* Supports SGlines */ 1, /* Supports SQlines */ 1, /* Supports SZlines */ @@ -678,6 +676,26 @@ class InspIRCdProto : public IRCDProto if (value && *value != ':' && strtoul((*value == '*' ? value + 1 : value), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end) return 1; else return 0; } + + void SetAutoIdentificationToken(User *u) + { + int *c; + char svidbuf[15]; + + if (!u->nc) + return; + + snprintf(svidbuf, sizeof(svidbuf), "%ld", u->timestamp); + + if (u->nc->GetExt("authenticationtoken", c)) + { + delete [] c; + u->nc->Shrink("authenticationtoken"); + } + + u->nc->Extend("authenticationtoken", sstrdup(svidbuf)); + } + } ircd_proto; @@ -1080,6 +1098,11 @@ int anope_event_nick(const char *source, int ac, const char **av) av[7], /* realname */ ts, htonl(*ad), av[3], NULL); if (user) { + /* InspIRCd1.1 has no user mode +d so we + * use nick timestamp to check for auth - Adam + */ + user->CheckAuthenticationToken(av[0]); + ircdproto->ProcessUsermodes(user, 1, &av[5]); user->chost = av[3]; } @@ -1348,7 +1371,21 @@ class ProtoInspIRCd : public Module pmodule_ircd_proto(&ircd_proto); moduleAddIRCDMsgs(); + + ModuleManager::Attach(I_OnDelCore, this); } + + void OnDelCore(NickCore *nc) + { + char *c; + + if (nc->GetExt("authenticationtoken", c)) + { + delete [] c; + nc->Shrink("authenticationtoken"); + } + } + }; MODULE_INIT("inspircd11", ProtoInspIRCd) diff --git a/src/protocol/inspircd12.cpp b/src/protocol/inspircd12.cpp index 7f1262df1..6be11646a 100644 --- a/src/protocol/inspircd12.cpp +++ b/src/protocol/inspircd12.cpp @@ -84,9 +84,7 @@ IRCDVar myIrcd[] = { "-q", /* Mode to unset for an owner */ "+a", /* Mode to set for channel admin */ "-a", /* Mode to unset for channel admin */ - "+r", /* Mode On Reg */ "-r", /* Mode on UnReg */ - "-r", /* Mode on Nick Change */ 0, /* Supports SGlines */ 1, /* Supports SQlines */ 1, /* Supports SZlines */ @@ -709,7 +707,19 @@ class InspIRCdProto : public IRCDProto void SendAccountLogin(User *u, NickCore *account) { + char *c; + send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display); + + if (account->GetExt("authenticationtoken", c)) + { + delete [] c; + account->Shrink("authenticationtoken"); + } + + account->Extend("authenticationtoken", sstrdup(account->display)); + + common_svsmode(u, "+rd", account->display); } void SendAccountLogout(User *u, NickCore *account) @@ -724,6 +734,7 @@ class InspIRCdProto : public IRCDProto return 0; return 1; } + } ircd_proto; @@ -1210,6 +1221,27 @@ int anope_event_whois(const char *source, int ac, const char **av) return MOD_CONT; } +int anope_event_metadata(const char *source, int ac, const char **av) +{ + User *u; + + if (ac < 3) + return MOD_CONT; + else if (!strcmp(av[1], "accountname")) + { + if ((u = find_byuid(av[0]))) + { + /* Check to see if the account name is the same + * as the one saved for this nick, if so identify + * them - Adam + */ + u->CheckAuthenticationToken(av[2]); + } + } + + return MOD_CONT; +} + int anope_event_capab(const char *source, int ac, const char **av) { int argc; @@ -1378,6 +1410,7 @@ void moduleAddIRCDMsgs() { m = createMessage("FTOPIC", anope_event_ftopic); addCoreMessage(IRCD,m); m = createMessage("OPERTYPE", anope_event_opertype); addCoreMessage(IRCD,m); m = createMessage("IDLE", anope_event_idle); addCoreMessage(IRCD,m); + m = createMessage("METADATA", anope_event_metadata); addCoreMessage(IRCD,m); } class ProtoInspIRCd : public Module @@ -1415,12 +1448,25 @@ class ProtoInspIRCd : public Module pmodule_ircd_proto(&ircd_proto); moduleAddIRCDMsgs(); + + ModuleManager::Attach(I_OnDelCore, this); } ~ProtoInspIRCd() { delete [] TS6SID; } + + void OnDelCore(NickCore *nc) + { + char *c; + + if (nc->GetExt("authenticationtoken", c)) + { + delete [] c; + nc->Shrink("authenticationtoken"); + } + } }; MODULE_INIT("inspircd12", ProtoInspIRCd) diff --git a/src/protocol/ratbox.c b/src/protocol/ratbox.c index ba560d115..c989dc004 100644 --- a/src/protocol/ratbox.c +++ b/src/protocol/ratbox.c @@ -60,9 +60,7 @@ IRCDVar myIrcd[] = { NULL, /* Mode to unset for an owner */ NULL, /* Mode to set for chan admin */ NULL, /* Mode to unset for chan admin */ - NULL, /* Mode On Reg */ - NULL, /* Mode on UnReg */ - NULL, /* Mode on Nick Change */ + NULL, /* Mode on UnReg */ 1, /* Supports SGlines */ 1, /* Supports SQlines */ 0, /* Supports SZlines */ @@ -684,6 +682,25 @@ class RatboxProto : public IRCDTS6Proto { send_cmd(bi->uid, "TOPIC %s :%s", chan, topic); } + + void SetAutoIdentificationToken(User *u) + { + char svidbuf[15], *c; + + if (!u->nc) + return; + + snprintf(svidbuf, sizeof(svidbuf), "%ld", u->timestamp); + + if (u->nc->GetExt("authenticationtoken", c)) + { + delete [] c; + u->nc->Shrink("authenticationtoken"); + } + + u->nc->Extend("authenticationtoken", sstrdup(svidbuf)); + } + } ircd_proto; @@ -732,6 +749,11 @@ int anope_event_nick(const char *source, int ac, const char **av) strtoul(av[2], NULL, 10), 0, "*", av[7]); if (user) { + /* No usermode +d on ratbox so we use + * nick timestamp to check for auth - Adam + */ + user->CheckAuthenticationToken(av[2]); + ircdproto->ProcessUsermodes(user, 1, &av[3]); } } else { @@ -1174,6 +1196,8 @@ class ProtoRatbox : public Module pmodule_ircd_proto(&ircd_proto); moduleAddIRCDMsgs(); + + ModuleManager::Attach(I_OnDelCore, this); } ~ProtoRatbox() @@ -1181,6 +1205,17 @@ class ProtoRatbox : public Module delete [] TS6SID; } + void OnDelCore(NickCore *nc) + { + char *c; + + if (nc->GetExt("authenticationtoken", c)) + { + delete [] c; + nc->Shrink("authenticationtoken"); + } + } + }; MODULE_INIT("ratbox", ProtoRatbox) diff --git a/src/protocol/unreal32.c b/src/protocol/unreal32.c index 773717495..b47b22368 100644 --- a/src/protocol/unreal32.c +++ b/src/protocol/unreal32.c @@ -97,9 +97,7 @@ IRCDVar myIrcd[] = { "-q", /* Mode to unset for an owner */ "+a", /* Mode to set for channel admin */ "-a", /* Mode to unset for channel admin */ - "+rd", /* Mode On Reg */ - "-r+d", /* Mode on UnReg */ - "-r+d", /* Mode on Nick Change */ + "-r+d", /* Mode on UnReg */ 1, /* Supports SGlines */ 1, /* Supports SQlines */ 1, /* Supports SZlines */ @@ -903,6 +901,28 @@ class UnrealIRCdProto : public IRCDProto return 1; } + void SetAutoIdentificationToken(User *u) + { + int *c; + char svidbuf[15]; + + if (!u->nc) + return; + + srand(time(NULL)); + snprintf(svidbuf, sizeof(svidbuf), "%i", rand()); + + if (u->nc->GetExt("authenticationtoken", c)) + { + delete [] c; + u->nc->Shrink("authenticationtoken"); + } + + u->nc->Extend("authenticationtoken", sstrdup(svidbuf)); + + common_svsmode(u, "+rd", svidbuf); + } + } ircd_proto; @@ -1223,7 +1243,14 @@ int anope_event_nick(const char *source, int ac, const char **av) user = do_nick(source, av[0], av[3], av[4], av[5], av[10], strtoul(av[2], NULL, 10), ntohl(decode_ip(av[9])), av[8], NULL); if (user) + { + /* Check to see if the user should be identified because their + * services id matches the one in their nickcore + */ + user->CheckAuthenticationToken(av[6]); + ircdproto->ProcessUsermodes(user, 1, &av[7]); + } } else { /* NON NICKIP */ @@ -1231,7 +1258,14 @@ int anope_event_nick(const char *source, int ac, const char **av) strtoul(av[2], NULL, 10), 0, av[8], NULL); if (user) + { + /* Check to see if the user should be identified because their + * services id matches the one in their nickcore + */ + user->CheckAuthenticationToken(av[6]); + ircdproto->ProcessUsermodes(user, 1, &av[7]); + } } } else { do_nick(source, av[0], NULL, NULL, NULL, NULL, @@ -1446,7 +1480,21 @@ class ProtoUnreal : public Module pmodule_ircd_proto(&ircd_proto); moduleAddIRCDMsgs(); + + ModuleManager::Attach(I_OnDelCore, this); + } + + void OnDelCore(NickCore *nc) + { + char *c; + + if (nc->GetExt("authenticationtoken", c)) + { + delete [] c; + nc->Shrink("authenticationtoken"); + } } + }; MODULE_INIT("unreal32", ProtoUnreal) diff --git a/src/users.c b/src/users.c index 07f1bb20c..8f51da449 100644 --- a/src/users.c +++ b/src/users.c @@ -137,9 +137,6 @@ const std::string &User::GetUID() const } - - - void User::SetVIdent(const std::string &sident) { this->vident = sident; @@ -176,9 +173,6 @@ const std::string &User::GetIdent() const } - - - void User::SetRealname(const std::string &srealname) { if (srealname.empty()) @@ -326,6 +320,34 @@ void User::SendMessage(const char *source, const std::string &msg) } } +/** Check if the user should become identified because + * their svid matches the one stored in their nickcore + * @param svid Services id + */ +void User::CheckAuthenticationToken(const char *svid) +{ + NickCore *tnc; + const char *c; + NickAlias *na; + + if ((tnc = findcore(this->nick))) + { + if (tnc->GetExt("authenticationtoken", c)) + { + if (svid && c && !strcmp(svid, c)) + { + /* Users authentication token matches so they should become identified */ + if ((na = findnick(this->nick))) + { + na->status |= NS_IDENTIFIED; + check_memos(this); + this->nc = tnc; + } + } + } + } +} + /*************************************************************************/ /*************************************************************************/ |