]> granicus.if.org Git - pdns/commitdiff
GSQL backend support for TSIG key management
authorAki Tuomi <cmouse@desteem.org>
Sat, 15 Jun 2013 14:04:50 +0000 (17:04 +0300)
committerAki Tuomi <cmouse@desteem.org>
Tue, 3 Sep 2013 15:17:33 +0000 (18:17 +0300)
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh

index 57c0f071f2368aed152de45a8987bd17b91430a0..8a997cd6ec21bd9b2b510d684d799364dabc5104 100644 (file)
@@ -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<KeyData>& keys)
 {
   if(!d_dnssecQueries)
index 2348ce5433c2c201e281ac2f51623909602babb3..1e53a98933c8b226fa5be3035cb94bccdc2b93f8 100644 (file)
@@ -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;