From: Aki Tuomi Date: Sat, 15 Jun 2013 14:04:50 +0000 (+0300) Subject: GSQL backend support for TSIG key management X-Git-Tag: rec-3.6.0-rc1~468^2~21 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a72349d41af5355f5ec2d2de3a91cb86627cc0e;p=pdns GSQL backend support for TSIG key management --- diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index 57c0f071f..8a997cd6e 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -314,6 +314,9 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix) d_RemoveDomainKeyQuery = getArg("remove-domain-key-query"); d_getTSIGKeyQuery = getArg("get-tsig-key-query"); + d_setTSIGKeyQuery = getArg("set-tsig-key-query"); + d_deleteTSIGKeyQuery = getArg("delete-tsig-key-query"); + d_getTSIGKeysQuery = getArg("get-tsig-keys-query"); } } @@ -602,6 +605,65 @@ bool GSQLBackend::getTSIGKey(const string& name, string* algorithm, string* cont return !content->empty(); } +bool GSQLBackend::setTSIGKey(const string& name, const string& algorithm, const string& content) +{ + if(!d_dnssecQueries) + return false; + + char output[1024]; + snprintf(output,sizeof(output)-1,d_setTSIGKeyQuery.c_str(), sqlEscape(toLower(name)).c_str(), sqlEscape(toLower(algorithm)).c_str(), sqlEscape(content).c_str()); + try { + d_db->doCommand(output); + } + catch (SSqlException &e) { + throw AhuException("GSQLBackend unable to store named TSIG key: "+e.txtReason()); + } + return true; +} + +bool GSQLBackend::deleteTSIGKey(const string& name) +{ + if(!d_dnssecQueries) + return false; + + char output[1024]; + snprintf(output,sizeof(output)-1,d_deleteTSIGKeyQuery.c_str(), sqlEscape(toLower(name)).c_str()); + try { + d_db->doCommand(output); + } + catch (SSqlException &e) { + throw AhuException("GSQLBackend unable to store named TSIG key: "+e.txtReason()); + } + return true; +} + +bool GSQLBackend::getTSIGKeys(std::vector< struct TSIGKey > &keys) +{ + if(!d_dnssecQueries) + return false; + + char output[1024]; + snprintf(output,sizeof(output)-1,"%s",d_getTSIGKeysQuery.c_str()); + + try { + d_db->doQuery(output); + } + catch (SSqlException &e) { + throw AhuException("GSQLBackend unable to retrieve named TSIG key: "+e.txtReason()); + } + + SSql::row_t row; + + while(d_db->getRow(row)) { + struct TSIGKey key; + key.name = row[0]; + key.algorithm = row[1]; + key.key = row[2]; + } + + return keys.empty(); +} + bool GSQLBackend::getDomainKeys(const string& name, unsigned int kind, std::vector& keys) { if(!d_dnssecQueries) diff --git a/pdns/backends/gsql/gsqlbackend.hh b/pdns/backends/gsql/gsqlbackend.hh index 2348ce543..1e53a9893 100644 --- a/pdns/backends/gsql/gsqlbackend.hh +++ b/pdns/backends/gsql/gsqlbackend.hh @@ -65,6 +65,10 @@ public: bool deactivateDomainKey(const string& name, unsigned int id); bool getTSIGKey(const string& name, string* algorithm, string* content); + bool setTSIGKey(const string& name, const string& algorithm, const string& content); + bool deleteTSIGKey(const string& name); + bool getTSIGKeys(std::vector< struct TSIGKey > &keys); + private: string d_qname; QType d_qtype; @@ -123,6 +127,9 @@ private: string d_DeactivateDomainKeyQuery; string d_getTSIGKeyQuery; + string d_setTSIGKeyQuery; + string d_deleteTSIGKeyQuery; + string d_getTSIGKeysQuery; string d_getAllDomainsQuery;