diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-05-24 19:34:25 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-06-07 01:00:10 +0200 |
commit | ad523652ae0ab92df728796a1f082f339f6ddbb6 (patch) | |
tree | 99bd6173894096ad482cf3f0222a302689c49837 /src | |
parent | 3d6d9cda32d72ff25cf6e624bb271b629898e018 (diff) |
Change the API of m_sslinfo to be dynamic_reference-based
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_sslinfo.cpp | 31 | ||||
-rw-r--r-- | src/modules/m_sslmodes.cpp | 32 |
2 files changed, 42 insertions, 21 deletions
diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp index 5516af7ef..edf3918e2 100644 --- a/src/modules/m_sslinfo.cpp +++ b/src/modules/m_sslinfo.cpp @@ -121,19 +121,37 @@ class CommandSSLInfo : public Command } }; +class UserCertificateAPIImpl : public UserCertificateAPIBase +{ + SSLCertExt& ext; + + public: + UserCertificateAPIImpl(Module* mod, SSLCertExt& certext) + : UserCertificateAPIBase(mod), ext(certext) + { + } + + ssl_cert* GetCertificate(User* user) CXX11_OVERRIDE + { + return ext.get(user); + } +}; + class ModuleSSLInfo : public Module { CommandSSLInfo cmd; + UserCertificateAPIImpl APIImpl; public: - ModuleSSLInfo() : cmd(this) + ModuleSSLInfo() + : cmd(this), APIImpl(this, cmd.CertExt) { } void init() CXX11_OVERRIDE { + ServerInstance->Modules->AddService(APIImpl); ServerInstance->Modules->AddService(cmd); - ServerInstance->Modules->AddService(cmd.CertExt); Implementation eventlist[] = { I_OnWhois, I_OnPreCommand, I_OnSetConnectClass, I_OnUserConnect, I_OnPostConnect }; @@ -228,15 +246,6 @@ class ModuleSSLInfo : public Module return MOD_RES_DENY; return MOD_RES_PASSTHRU; } - - void OnRequest(Request& request) CXX11_OVERRIDE - { - if (strcmp("GET_USER_CERT", request.id) == 0) - { - UserCertificateRequest& req = static_cast<UserCertificateRequest&>(request); - req.cert = cmd.CertExt.get(req.user); - } - } }; MODULE_INIT(ModuleSSLInfo) diff --git a/src/modules/m_sslmodes.cpp b/src/modules/m_sslmodes.cpp index 360f63bc9..65933cc14 100644 --- a/src/modules/m_sslmodes.cpp +++ b/src/modules/m_sslmodes.cpp @@ -31,7 +31,13 @@ class SSLMode : public ModeHandler { public: - SSLMode(Module* Creator) : ModeHandler(Creator, "sslonly", 'z', PARAM_NONE, MODETYPE_CHANNEL) { } + UserCertificateAPI API; + + SSLMode(Module* Creator) + : ModeHandler(Creator, "sslonly", 'z', PARAM_NONE, MODETYPE_CHANNEL) + , API(Creator) + { + } ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) { @@ -41,12 +47,14 @@ class SSLMode : public ModeHandler { if (IS_LOCAL(source)) { + if (!API) + return MODEACTION_DENY; + const UserMembList* userlist = channel->GetUsers(); for(UserMembCIter i = userlist->begin(); i != userlist->end(); i++) { - UserCertificateRequest req(i->first, creator); - req.Send(); - if(!req.cert && !ServerInstance->ULine(i->first->server)) + ssl_cert* cert = API->GetCertificate(i->first); + if (!cert && !ServerInstance->ULine(i->first->server)) { source->WriteNumeric(ERR_ALLMUSTSSL, "%s %s :all members of the channel must be connected via SSL", source->nick.c_str(), channel->name.c_str()); return MODEACTION_DENY; @@ -96,9 +104,11 @@ class ModuleSSLModes : public Module { if(chan && chan->IsModeSet('z')) { - UserCertificateRequest req(user, this); - req.Send(); - if (req.cert) + if (!sslm.API) + return MOD_RES_DENY; + + ssl_cert* cert = sslm.API->GetCertificate(user); + if (cert) { // Let them in return MOD_RES_PASSTHRU; @@ -118,9 +128,11 @@ class ModuleSSLModes : public Module { if ((mask.length() > 2) && (mask[0] == 'z') && (mask[1] == ':')) { - UserCertificateRequest req(user, this); - req.Send(); - if (req.cert && InspIRCd::Match(req.cert->GetFingerprint(), mask.substr(2))) + if (!sslm.API) + return MOD_RES_DENY; + + ssl_cert* cert = sslm.API->GetCertificate(user); + if (cert && InspIRCd::Match(cert->GetFingerprint(), mask.substr(2))) return MOD_RES_DENY; } return MOD_RES_PASSTHRU; |