#include "inspircd.h" #include "transport.h" class ModuleFingerprint : public Module { public: ModuleFingerprint(InspIRCd* Me) : Module(Me) { Implementation eventlist[] = { I_OnDecodeMetaData, I_OnSyncUserMetaData, I_OnPostConnect, I_OnUserQuit, I_OnCleanup }; ServerInstance->Modules->Attach(eventlist, this, 5); } // Whenever the linking module receives metadata from another server and doesnt know what // to do with it (of course, hence the 'meta') it calls this method, and it is up to each // module in turn to figure out if this metadata key belongs to them, and what they want // to do with it. // In our case we're only sending a single string around, so we just construct a std::string. // Some modules will probably get much more complex and format more detailed structs and classes // in a textual way for sending over the link. virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata) { // check if its our metadata key, and its associated with a user if ((target_type == TYPE_USER) && (extname == "fingerprint")) { User* dest = (User*)target; std::string* text; if (dest->GetExt("fingerprint", text)) { dest->Shrink("fingerprint"); delete text; } if (extdata.empty()) return; text = new std::string(extdata); dest->Extend("fingerprint", text); } } // Whenever the linking module wants to send out data, but doesnt know what the data // represents (e.g. it is metadata, added to a User or Channel by a module) then // this method is called. We should use the ProtoSendMetaData function after we've // corrected decided how the data should look, to send the metadata on its way if // it is ours. virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable) { // because we dont store the fingerprint if (IS_LOCAL(user)), // the OnSyncUserMetaData is never called with extname="fingerprint". // so we want to sync the fingerprint data on each "ssl" sync if (extname == "ssl") { std::string* fingerprint; ssl_cert* cert; if (user->GetExt("ssl_cert", cert)) { proto->ProtoSendMetaData(opaque, TYPE_USER, user, "fingerprint", cert->GetFingerprint()); } else if (user->GetExt("fingerprint", fingerprint)) { proto->ProtoSendMetaData(opaque, TYPE_USER, user, "fingerprint", *fingerprint); } } } virtual void OnPostConnect(User* user) { if ((IS_LOCAL(user))) { ssl_cert *cert; if (user->GetExt("ssl_cert", cert)) { ServerInstance->PI->SendMetaData(user, TYPE_USER, "fingerprint", cert->GetFingerprint()); } } } virtual void OnUserQuit(User* user, const std::string &message, const std::string &oper_message) { std::string* fingerprint; if (user->GetExt("fingerprint", fingerprint)) { user->Shrink("fingerprint"); delete fingerprint; } } virtual void OnCleanup(int target_type, void* item) { if (target_type == TYPE_USER) { User* user = (User*)item; std::string* fingerprint; if (user->GetExt("fingerprint", fingerprint)) { user->Shrink("fingerprint"); delete fingerprint; } } } virtual Version GetVersion() { return Version("$Id: m_ssl_fingerprint v1.0 2009-03-28 DukePyrolator $", VF_VENDOR, API_VERSION); } }; MODULE_INIT(ModuleFingerprint)