1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 // Password description - method, authdata
19 typedef std::pair<std::string, std::string> passdesc;
20 typedef std::multimap<std::string,passdesc> AuthMap;
22 class ModuleAuthCache : public Module
33 Implementation eventlist[] = { I_OnCheckReady, I_OnDecodeMetaData, I_OnSyncNetwork };
34 ServerInstance->Modules->Attach(eventlist, this, 3);
37 void OnSyncNetwork(Module* proto, void* opaque)
39 for(AuthMap::iterator it = usernames.begin(); it != usernames.end(); it++)
40 proto->ProtoSendMetaData(opaque, NULL, "authcache", it->second.first +
41 " " + it->first + " " + it->second.second);
44 void OnDecodeMetaData(Extensible* dest, const std::string& name, const std::string& value)
46 if (dest || name != "authcache")
48 irc::spacesepstream splitter(value);
49 std::string method, id, data;
50 splitter.GetToken(method);
51 splitter.GetToken(id);
52 data = splitter.GetRemaining();
54 std::pair<AuthMap::iterator, AuthMap::iterator> it = usernames.equal_range(id);
55 while (it.first != it.second)
57 if (it.first->second.first == method)
59 usernames.erase(it.first);
67 usernames.insert(std::make_pair(id, std::make_pair(method, data)));
71 ModResult OnCheckReady(LocalUser* user)
75 std::pair<AuthMap::iterator, AuthMap::iterator> it = usernames.equal_range(user->nick);
76 while (it.first != it.second)
78 if (!ServerInstance->PassCompare(user, it.first->second.second, user->password, it.first->second.first))
83 SocketCertificateRequest req(&user->eh, this);
87 it = usernames.equal_range(req.cert->GetFingerprint());
88 while (it.first != it.second)
90 if (it.first->second.first == "sslfp")
91 login = it.first->second.second;
98 AccountExtItem* ext = GetAccountExtItem();
101 ext->set(user, login);
102 AccountEvent(this, user, login).Send();
105 return MOD_RES_PASSTHRU;
110 return Version("Provides an authorization cache for user accounts", VF_OPTCOMMON | VF_VENDOR);
114 MODULE_INIT(ModuleAuthCache)