From 89594d455718432a24930a7cf97c26daaaf49472 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 21 Feb 2024 13:11:47 +0000 Subject: Add a method to the ns_cert API for replacing a certificate. This will be used for upgrading certificate fingerprints when the InspIRCd 1206 protocol support is added. --- include/modules/ns_cert.h | 9 +++++++++ modules/nickserv/ns_cert.cpp | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/modules/ns_cert.h b/include/modules/ns_cert.h index 2d24cfeae..804643e77 100644 --- a/include/modules/ns_cert.h +++ b/include/modules/ns_cert.h @@ -54,6 +54,15 @@ public: */ virtual void EraseCert(const Anope::string &entry) = 0; + /** Replaces a fingerprint in the nick's certificate list + * + * @param oldentry The old fingerprint to remove + * @param newentry The new fingerprint to add + * + * Replaces the specified fingerprint in the cert list. + */ + virtual void ReplaceCert(const Anope::string &oldentry, const Anope::string &newentry) = 0; + /** Clears the entire nick's cert list * * Deletes all the memory allocated in the certificate list vector and then clears the vector. diff --git a/modules/nickserv/ns_cert.cpp b/modules/nickserv/ns_cert.cpp index 389b49cf5..17cf1fb96 100644 --- a/modules/nickserv/ns_cert.cpp +++ b/modules/nickserv/ns_cert.cpp @@ -103,6 +103,19 @@ public: } } + void ReplaceCert(const Anope::string &oldentry, const Anope::string &newentry) override + { + auto it = std::find(this->certs.begin(), this->certs.end(), oldentry); + if (it == this->certs.end()) + return; // We can't replace a non-existent cert. + + FOREACH_MOD(OnNickEraseCert, (this->nc, oldentry)); + certmap.erase(oldentry); + *it = newentry; + certmap[newentry] = nc; + FOREACH_MOD(OnNickAddCert, (this->nc, newentry)); + } + /** Clears the entire nick's cert list * * Deletes all the memory allocated in the certificate list vector and then clears the vector. -- cgit