From 9c6c256f4b7a9294b6c8c6e4f7ebfeeb66b391a6 Mon Sep 17 00:00:00 2001 From: Benjamin Zengin Date: Tue, 5 Jul 2016 11:54:52 +0200 Subject: [PATCH] Implements 'return id of added key' for bind --- modules/bindbackend/bindbackend2.cc | 1 + modules/bindbackend/bindbackend2.hh | 1 + modules/bindbackend/binddnssec.cc | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index 3baf25ebb..9429903ee 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -610,6 +610,7 @@ Bind2Backend::Bind2Backend(const string &suffix, bool loadZones) d_getDomainKeysQuery_stmt = NULL; d_deleteDomainKeyQuery_stmt = NULL; d_insertDomainKeyQuery_stmt = NULL; + d_GetLastInsertedKeyIdQuery_stmt = NULL; d_activateDomainKeyQuery_stmt = NULL; d_deactivateDomainKeyQuery_stmt = NULL; d_getTSIGKeyQuery_stmt = NULL; diff --git a/modules/bindbackend/bindbackend2.hh b/modules/bindbackend/bindbackend2.hh index a93b44805..114323ae5 100644 --- a/modules/bindbackend/bindbackend2.hh +++ b/modules/bindbackend/bindbackend2.hh @@ -289,6 +289,7 @@ private: SSqlStatement* d_getDomainKeysQuery_stmt; SSqlStatement* d_deleteDomainKeyQuery_stmt; SSqlStatement* d_insertDomainKeyQuery_stmt; + SSqlStatement* d_GetLastInsertedKeyIdQuery_stmt; SSqlStatement* d_activateDomainKeyQuery_stmt; SSqlStatement* d_deactivateDomainKeyQuery_stmt; SSqlStatement* d_getTSIGKeyQuery_stmt; diff --git a/modules/bindbackend/binddnssec.cc b/modules/bindbackend/binddnssec.cc index f6d90d778..ba57339b5 100644 --- a/modules/bindbackend/binddnssec.cc +++ b/modules/bindbackend/binddnssec.cc @@ -114,6 +114,7 @@ void Bind2Backend::setupStatements() d_getDomainKeysQuery_stmt = d_dnssecdb->prepare("select id,flags, active, content from cryptokeys where domain=:domain",1); d_deleteDomainKeyQuery_stmt = d_dnssecdb->prepare("delete from cryptokeys where domain=:domain and id=:key_id",2); d_insertDomainKeyQuery_stmt = d_dnssecdb->prepare("insert into cryptokeys (domain, flags, active, content) values (:domain, :flags, :active, :content)", 4); + d_GetLastInsertedKeyIdQuery_stmt = d_dnssecdb->prepare("select last_insert_rowid()", 0); d_activateDomainKeyQuery_stmt = d_dnssecdb->prepare("update cryptokeys set active=1 where domain=:domain and id=:key_id", 2); d_deactivateDomainKeyQuery_stmt = d_dnssecdb->prepare("update cryptokeys set active=0 where domain=:domain and id=:key_id", 2); d_getTSIGKeyQuery_stmt = d_dnssecdb->prepare("select algorithm, secret from tsigkeys where name=:key_name", 1); @@ -136,6 +137,7 @@ void Bind2Backend::freeStatements() release(&d_getDomainKeysQuery_stmt); release(&d_deleteDomainKeyQuery_stmt); release(&d_insertDomainKeyQuery_stmt); + release(&d_GetLastInsertedKeyIdQuery_stmt); release(&d_activateDomainKeyQuery_stmt); release(&d_deactivateDomainKeyQuery_stmt); release(&d_getTSIGKeyQuery_stmt); @@ -323,7 +325,22 @@ int Bind2Backend::addDomainKey(const DNSName& name, const KeyData& key) catch(SSqlException& se) { throw PDNSException("Error accessing DNSSEC database in BIND backend, addDomainKey(): "+se.txtReason()); } - return true; + + try { + d_GetLastInsertedKeyIdQuery_stmt->execute(); + if (!d_GetLastInsertedKeyIdQuery_stmt->hasNextRow()) + throw PDNSException("GSQLBackend unable to get id"); + SSqlStatement::row_t row; + d_GetLastInsertedKeyIdQuery_stmt->nextRow(row); + int id = std::stoi(row[0]); + d_GetLastInsertedKeyIdQuery_stmt->reset(); + return id; + } + catch (SSqlException &e) { + throw PDNSException("DNSSEC database in BIND backend unable to get id: "+e.txtReason()); + } + + return -1; } bool Bind2Backend::activateDomainKey(const DNSName& name, unsigned int id) -- 2.40.0